From dcc2811bc83d3b5fe730040240da58f172d813d6 Mon Sep 17 00:00:00 2001 From: KaiTomotake Date: Sun, 18 Jan 2026 22:06:03 +0900 Subject: [PATCH 1/3] add TypeId.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit anyモジュールのフォルダーにTypeId.mdを追加 --- src/any/TypeId.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/any/TypeId.md diff --git a/src/any/TypeId.md b/src/any/TypeId.md new file mode 100644 index 0000000..e69de29 From f58bf378217183e552e9ee63d81211d9a9151f1e Mon Sep 17 00:00:00 2001 From: KaiTomotake Date: Tue, 20 Jan 2026 20:42:52 +0900 Subject: [PATCH 2/3] add TypeId.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TypeId構造体のリファレンスを追加 --- src/SUMMARY.md | 1 + src/any/TypeId.md | 240 ++++++++++++++++++++++++++++++++++++++++++++++ src/any/about.md | 2 +- 3 files changed, 242 insertions(+), 1 deletion(-) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 3534392..3c34dd5 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -7,6 +7,7 @@ # リファレンス - [std::any](./any/about.md) + - [TypeId](./any/TypeId.md) - [std::vec](./vec/about.md) - [Drain](./vec/Drain.md) diff --git a/src/any/TypeId.md b/src/any/TypeId.md index e69de29..1b99f75 100644 --- a/src/any/TypeId.md +++ b/src/any/TypeId.md @@ -0,0 +1,240 @@ +# 構造体 `std::any::TypeId` + +```rust,ignore +pub struct TypeId { + // private fields +} +``` +## バージョン + +Rust 1.0.0 ~ + +## 解説 + +型に対するグローバルに一意な識別子を提供する構造体。 +不透明なオブジェクトであるため内部を直接見ることはできないが、cloneやdebugといった基本的な操作は可能である。 + +現在、`TypeId`は`'static`制約を満たすもののみ利用できるが、これは将来解除される可能性がある。 + +また、`Hash`や`Ord`、`PartialOrd`を実装しているが、ハッシュ値や順序はRustのリリースごとに違うため、これらに依存した設計は避けるべきである。 + +## 実装 + +```rust,ignore +impl TypeId { + pub const fn of() -> TypeId + where + T: 'static + ?Sized; +} +``` + +### `of` + +ジェネリクスに渡された型のTypeIdを返す関数。 + +```rust +use std::any::TypeId; + +fn is_i32(val: T) -> bool { + TypeId::of::() == TypeId::of::() +} + +assert!(!is_i32(1.2)); +``` + +## トレイト実装 + +### `Clone` + +```rust,ignore +impl Clone for TypeId { + /* trait methods */ +} +``` + +### `std::fmt::Debug` + +```rust,ignore +impl std::fmt::Debug for TypeId { + /* trait methods */ +} +``` + +### `std::hash::Hash` + +```rust,ignore +impl std::hash::Hash for TypeId { + /* trait methods */ +} +``` + +### `Ord` + +```rust,ignore +impl Ord for TypeId { + /* trait methods */ +} +``` + +### `PartialEq` + +```rust,ignore +impl PartialEq for TypeId { + /* trait methods */ +} +``` + +### `PartialOrd` + +```rust,ignore +impl PartialOrd for TypeId { + /* trait methods */ +} +``` + +### `Copy` + +```rust,ignore +impl Copy for TypeId {} +``` + +### `Eq` + +```rust,ignore +impl Eq for TypeId {} +``` + +### `Send` + +```rust,ignore +impl Send for TypeId {} +``` + +### `Sync` + +```rust,ignore +impl Sync for TypeId {} +``` + +### `std::marker::Freeze` + +```rust,ignore +impl std::marker::Freeze for TypeId {} +``` + +### `std::panic::RefUnwindSafe` + +```rust,ignore +impl std::panic::RefUnwindSafe for TypeId {} +``` + +### `Unpin` + +```rust,ignore +impl Unpin for TypeId {} +``` + +### `std::panic::UnwindSafe` + +```rust,ignore +impl std::panic::UnwindSafe for TypeId {} +``` + +--- + +### `std::any::Any` + +```rust,ignore +impl std::any::Any for T +where + T: 'static + ?Sized, +{ + /* trait methods */ +} +``` + +### `std::borrow::Borrow` + +```rust,ignore +impl std::borrow::Borrow for T +where + T: ?Sized, +{ + /* trait methods */ +} +``` + +### `std::borrow::BorrowMut` + +```rust,ignore +impl std::borrow::BorrowMut for T +where + T: ?Sized, +{ + /* trait methods */ +} +``` + +### `std::clone::CloneToUninit` + +```rust,ignore +impl std::clone::CloneToUninit for T +where + T: Clone, +{ + /* trait methods */ +} +``` + +### `From` + +```rust,ignore +impl From for T { + /* trait methods */ +} +``` + +### `Into` + +```rust,ignore +impl Into for T +where + U: From, +{ + /* trait methods */ +} +``` + +### `std::borrow::ToOwned` + +```rust,ignore +impl std::borrow::ToOwned for T +where + T: Clone, +{ + /* trait methods */ +} +``` + +### `TryFrom` + +```rust,ignore +impl TryFrom for T +where + U: Into, +{ + /* trait methods */ +} +``` + +### `TryInto` + +```rust,ignore +impl TryInto for T +where + U: TryFrom, +{ + /* trait methods */ +} +``` + diff --git a/src/any/about.md b/src/any/about.md index 6e98826..ecf7768 100644 --- a/src/any/about.md +++ b/src/any/about.md @@ -12,7 +12,7 @@ Rust 1.0.0 ~ | 名前 | 説明 | | --- | --- | -| `TypeId` | グローバルに一意な型の識別子を提供する | +| [`TypeId`](./TypeId.md) | グローバルに一意な型の識別子を提供する | ## トレイト From ee09f0c61e196f15cdc5d9b4569b81b07c414085 Mon Sep 17 00:00:00 2001 From: KaiTomotake Date: Thu, 22 Jan 2026 11:33:47 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E8=A1=A8=E7=8F=BE=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/any/TypeId.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/any/TypeId.md b/src/any/TypeId.md index 1b99f75..fc03533 100644 --- a/src/any/TypeId.md +++ b/src/any/TypeId.md @@ -12,7 +12,7 @@ Rust 1.0.0 ~ ## 解説 型に対するグローバルに一意な識別子を提供する構造体。 -不透明なオブジェクトであるため内部を直接見ることはできないが、cloneやdebugといった基本的な操作は可能である。 +不透明なオブジェクトであるため内部を直接見ることはできないが、DebugやCloneといった基本的なトレイトは実装してある。 現在、`TypeId`は`'static`制約を満たすもののみ利用できるが、これは将来解除される可能性がある。