-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
[Merged by Bors] - bevy_reflect: Add statically available type info for reflected types #4042
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
Closed
Closed
Changes from 23 commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
ed5e997
Added TypeInfo
MrGVSV bfcfa25
Added tests
MrGVSV 190dbc2
Fix clippy warnings
MrGVSV ea49152
Formatting
MrGVSV 0ec2270
Apply suggestions from code review
MrGVSV b0dfaa9
Added relevant TypeIds to info structs
MrGVSV 23e276a
Formatting
MrGVSV 83c5e6e
Added convenience methods to TypeInfo
MrGVSV 81c1298
Added Typed trait
MrGVSV 8ad235c
Formatting
MrGVSV e9f39cf
Impl Typed for dyn Reflect
MrGVSV ad786ad
Formatting
MrGVSV a5ca84d
Replaced Cow<'static, str> with &'static str
MrGVSV f8e57a9
Store fields as Box<[T]>
MrGVSV fea5343
Added documentation for DynamicInfo
MrGVSV 091e5e8
Added TypeIdentity
MrGVSV 8cf5029
Integrated TypeIdentity across type info structs
MrGVSV 9cbaf28
Fixed doc error
MrGVSV f6cbb1d
Remove duplicated data
MrGVSV 55e023b
Removed unnecessary methods
MrGVSV 000c327
Clarify comments
MrGVSV 097b1f2
Added static_new method to create field with static str
MrGVSV d1ddb1f
Use the cow
MrGVSV 4fcc07f
Merge branch 'main' into reflect-type-info
MrGVSV 1f89001
Merge branch 'main' into reflect-type-info
MrGVSV 018a125
Merge branch 'main' into reflect-type-info
MrGVSV 8d93a67
Merge branch 'main' into reflect-type-info
MrGVSV be284d6
Merge branch 'reflect-type-info' of https://github.com/MrGVSV/bevy in…
MrGVSV ab8d022
Resolve merge conflict
MrGVSV 9a41c85
Formatting
MrGVSV 16d3ab6
Fix doc wording
MrGVSV ea9d34b
Add Reflect::get_type_info
MrGVSV d2f8f9f
Merge branch 'main' into reflect-type-info
MrGVSV 5544557
Renamed name -> type_name
MrGVSV 5d97ea5
Formatting
MrGVSV 43dda0a
Remove unused import
MrGVSV 51e1214
Removed TypeIdentity
MrGVSV 4c0040a
Change doc wording
MrGVSV c3c54cb
Combine constructors
MrGVSV a877911
Return static TypeInfo from Typed::type_info()
MrGVSV 63c284f
Remove extraneous import
MrGVSV aa5178e
Fix clippy warnings
MrGVSV c18cf5c
Merge branch 'main' into reflect-type-info
MrGVSV e87c24b
Fix incorrect non-generic TypeInfoCell
MrGVSV 1e7cbd8
Use TypeInfo to default trait methods
MrGVSV 87f1069
Merge branch 'main' into reflect-type-info
MrGVSV ee38b76
Improve docs
MrGVSV f8b4d07
Remove ListInfo capacity
MrGVSV 38b2611
Replace list capacity references
MrGVSV 16b7938
Revert "Use TypeInfo to default trait methods"
MrGVSV c0495e5
Split up TypeInfoCell
MrGVSV 0fc6b64
Change wording in docs
MrGVSV 6ddb85a
Merge remote-tracking branch 'origin/main' into pr/MrGVSV/4042-1
cart 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,66 @@ | ||
| use crate::{Reflect, TypeIdentity}; | ||
| use std::borrow::Cow; | ||
|
|
||
| /// The named field of a reflected struct | ||
| #[derive(Clone, Debug)] | ||
| pub struct NamedField { | ||
| name: Cow<'static, str>, | ||
| id: TypeIdentity, | ||
| } | ||
|
|
||
| impl NamedField { | ||
| /// Create a new [`NamedField`] | ||
| pub fn new<T: Reflect>(name: &str) -> Self { | ||
|
MrGVSV marked this conversation as resolved.
Outdated
|
||
| Self { | ||
| name: Cow::Owned(name.into()), | ||
| id: TypeIdentity::of::<T>(), | ||
| } | ||
| } | ||
|
|
||
| /// Create a new [`NamedField`] using a static string | ||
| /// | ||
| /// This helps save an allocation when the string has a static lifetime, such | ||
| /// as when using [`std::any::type_name`]. | ||
| pub fn static_new<T: Reflect>(name: &'static str) -> Self { | ||
|
MrGVSV marked this conversation as resolved.
Outdated
|
||
| Self { | ||
| name: Cow::Borrowed(name), | ||
| id: TypeIdentity::of::<T>(), | ||
| } | ||
| } | ||
|
|
||
| /// The name of the field | ||
| pub fn name(&self) -> &Cow<'static, str> { | ||
| &self.name | ||
| } | ||
|
|
||
| /// The [`TypeIdentity`] of the field | ||
| pub fn id(&self) -> &TypeIdentity { | ||
| &self.id | ||
| } | ||
| } | ||
|
|
||
| /// The unnamed field of a reflected tuple or tuple struct | ||
| #[derive(Clone, Debug)] | ||
| pub struct UnnamedField { | ||
| index: usize, | ||
| id: TypeIdentity, | ||
| } | ||
|
|
||
| impl UnnamedField { | ||
| pub fn new<T: Reflect>(index: usize) -> Self { | ||
| Self { | ||
| index, | ||
| id: TypeIdentity::of::<T>(), | ||
| } | ||
| } | ||
|
|
||
| /// Returns the index of the field | ||
| pub fn index(&self) -> usize { | ||
| self.index | ||
| } | ||
|
|
||
| /// The [`TypeIdentity`] of the field | ||
| pub fn id(&self) -> &TypeIdentity { | ||
| &self.id | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.