-
Notifications
You must be signed in to change notification settings - Fork 4
add TypeId.md #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KaiTomotake
wants to merge
3
commits into
Rust-Developers-JP:main
Choose a base branch
from
KaiTomotake:add-typeid-reference
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+242
−1
Open
add TypeId.md #27
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,240 @@ | ||
| # 構造体 `std::any::TypeId` | ||
|
|
||
| ```rust,ignore | ||
| pub struct TypeId { | ||
| // private fields | ||
| } | ||
| ``` | ||
| ## バージョン | ||
|
|
||
| Rust 1.0.0 ~ | ||
|
|
||
| ## 解説 | ||
|
|
||
| 型に対するグローバルに一意な識別子を提供する構造体。 | ||
| 不透明なオブジェクトであるため内部を直接見ることはできないが、DebugやCloneといった基本的なトレイトは実装してある。 | ||
|
|
||
| 現在、`TypeId`は`'static`制約を満たすもののみ利用できるが、これは将来解除される可能性がある。 | ||
|
|
||
| また、`Hash`や`Ord`、`PartialOrd`を実装しているが、ハッシュ値や順序はRustのリリースごとに違うため、これらに依存した設計は避けるべきである。 | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Danger of Improper VarianceとExamplesが省略されています.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 見逃していました。追加します |
||
| ## 実装 | ||
|
|
||
| ```rust,ignore | ||
| impl TypeId { | ||
| pub const fn of<T>() -> TypeId | ||
| where | ||
| T: 'static + ?Sized; | ||
| } | ||
| ``` | ||
|
|
||
| ### `of` | ||
|
|
||
| ジェネリクスに渡された型のTypeIdを返す関数。 | ||
|
|
||
| ```rust | ||
| use std::any::TypeId; | ||
|
|
||
| fn is_i32<T: 'static + ?Sized>(val: T) -> bool { | ||
| TypeId::of::<T>() == TypeId::of::<i32>() | ||
| } | ||
|
|
||
| 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<T> std::any::Any for T | ||
| where | ||
| T: 'static + ?Sized, | ||
| { | ||
| /* trait methods */ | ||
| } | ||
| ``` | ||
|
|
||
| ### `std::borrow::Borrow` | ||
|
|
||
| ```rust,ignore | ||
| impl<T> std::borrow::Borrow<T> for T | ||
| where | ||
| T: ?Sized, | ||
| { | ||
| /* trait methods */ | ||
| } | ||
| ``` | ||
|
|
||
| ### `std::borrow::BorrowMut` | ||
|
|
||
| ```rust,ignore | ||
| impl<T> std::borrow::BorrowMut<T> for T | ||
| where | ||
| T: ?Sized, | ||
| { | ||
| /* trait methods */ | ||
| } | ||
| ``` | ||
|
|
||
| ### `std::clone::CloneToUninit` | ||
|
|
||
| ```rust,ignore | ||
| impl<T> std::clone::CloneToUninit for T | ||
| where | ||
| T: Clone, | ||
| { | ||
| /* trait methods */ | ||
| } | ||
| ``` | ||
|
|
||
| ### `From` | ||
|
|
||
| ```rust,ignore | ||
| impl<T> From<T> for T { | ||
| /* trait methods */ | ||
| } | ||
| ``` | ||
|
|
||
| ### `Into` | ||
|
|
||
| ```rust,ignore | ||
| impl<T, U> Into<U> for T | ||
| where | ||
| U: From<T>, | ||
| { | ||
| /* trait methods */ | ||
| } | ||
| ``` | ||
|
|
||
| ### `std::borrow::ToOwned` | ||
|
|
||
| ```rust,ignore | ||
| impl<T> std::borrow::ToOwned for T | ||
| where | ||
| T: Clone, | ||
| { | ||
| /* trait methods */ | ||
| } | ||
| ``` | ||
|
|
||
| ### `TryFrom` | ||
|
|
||
| ```rust,ignore | ||
| impl<T, U> TryFrom<U> for T | ||
| where | ||
| U: Into<T>, | ||
| { | ||
| /* trait methods */ | ||
| } | ||
| ``` | ||
|
|
||
| ### `TryInto` | ||
|
|
||
| ```rust,ignore | ||
| impl<T, U> TryInto<U> for T | ||
| where | ||
| U: TryFrom<T>, | ||
| { | ||
| /* trait methods */ | ||
| } | ||
| ``` | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
意図が入っていますが,こちらの方がいいと思われます.