-
Notifications
You must be signed in to change notification settings - Fork 52
feat: Add bevy-reflect feature #439
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
TeamDman
wants to merge
10
commits into
ParkMyCar:main
Choose a base branch
from
TeamDman:mine
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.
Open
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e6142fc
feat: Add bevy-reflect feature
TeamDman c2b9181
feat: Add bevy example
TeamDman b4720fa
chore: Clean up bevy-reflect feature
TeamDman d538f03
chore: Restore bevy-reflect feature example
TeamDman 4810ca1
Fix bevy example workspace member
TeamDman 68bc8c4
Update to bevy-reflect 0.17.0-rc.2
TeamDman bcf39d4
Add more tests ensuring derive macro functions as expected
TeamDman 60cd3f0
Update to Bevy 0.17.1
TeamDman ca84351
Update compact_str/src/features/bevy_reflect.rs
TeamDman 76c987d
Update compact_str/Cargo.toml
TeamDman 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
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,67 @@ | ||
| use crate::CompactString; | ||
| use bevy_reflect::{ | ||
| impl_reflect_opaque, std_traits::ReflectDefault, ReflectDeserialize, ReflectSerialize, | ||
| }; | ||
|
|
||
| impl_reflect_opaque!((in crate::CompactString)CompactString( | ||
| Clone, | ||
| Debug, | ||
| Hash, | ||
| PartialEq, | ||
| Default, | ||
| Serialize, | ||
| Deserialize, | ||
| )); | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use crate::CompactString; | ||
| use bevy_reflect::{FromReflect, PartialReflect, Reflect}; | ||
|
|
||
| #[derive(Debug, Reflect, Eq, PartialEq)] | ||
| struct MyTestComponentStruct { | ||
| pub value: CompactString, | ||
| } | ||
|
|
||
TeamDman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #[derive(Debug, Reflect, Eq, PartialEq)] | ||
| struct MyTestComponentTuple(pub CompactString); | ||
|
|
||
| #[test] | ||
| fn should_partial_eq_compactstring() { | ||
| let a: &dyn PartialReflect = &CompactString::new("A"); | ||
| let a2: &dyn PartialReflect = &CompactString::new("A"); | ||
| let b: &dyn PartialReflect = &CompactString::new("B"); | ||
| assert_eq!(Some(true), a.reflect_partial_eq(a2)); | ||
| assert_eq!(Some(false), a.reflect_partial_eq(b)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn compactstring_should_from_reflect() { | ||
| let string = CompactString::new("hello_world.rs"); | ||
| let output = <CompactString as FromReflect>::from_reflect(&string); | ||
| assert_eq!(Some(string), output); | ||
| } | ||
|
|
||
| #[test] | ||
| fn compactstring_heap_should_from_reflect() { | ||
| let string = CompactString::new("abc".repeat(100)); | ||
| let output = <CompactString as FromReflect>::from_reflect(&string); | ||
| assert_eq!(Some(string), output); | ||
| } | ||
|
|
||
| #[test] | ||
| fn struct_with_compactstring_should_from_reflect() { | ||
| let string = CompactString::new("hello_world.rs"); | ||
| let my_struct = MyTestComponentStruct { value: string }; | ||
| let output = <MyTestComponentStruct as FromReflect>::from_reflect(&my_struct); | ||
| assert_eq!(Some(my_struct), output); | ||
| } | ||
|
|
||
| #[test] | ||
| fn tuple_with_compactstring_should_from_reflect() { | ||
| let string = CompactString::new("hello_world.rs"); | ||
| let my_struct = MyTestComponentTuple(string); | ||
| let output = <MyTestComponentTuple as FromReflect>::from_reflect(&my_struct); | ||
| assert_eq!(Some(my_struct), output); | ||
| } | ||
| } | ||
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,9 @@ | ||
| [package] | ||
| name = "example-bevy" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [dependencies] | ||
| compact_str = { version = "0.9.0", features = ["bevy-reflect"], path="../../compact_str" } | ||
| bevy_ecs = "0.17.1" | ||
| bevy_reflect = "0.17.1" |
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,21 @@ | ||
| use bevy_ecs::component::Component; | ||
| use bevy_ecs::prelude::Entity; | ||
| use bevy_ecs::world::World; | ||
| use bevy_reflect::Reflect; | ||
| use compact_str::CompactString; | ||
|
|
||
| #[derive(Component, Reflect, Debug)] | ||
| pub struct Thing(pub CompactString); | ||
|
|
||
| pub fn main() { | ||
| let mut world = World::default(); | ||
|
|
||
| let thing1 = Thing(CompactString::new("Hello, world!")); | ||
| let thing2 = Thing(CompactString::new("Goodbye, world!")); | ||
| world.spawn(thing1); | ||
| world.spawn(thing2); | ||
|
|
||
| for thing in world.query::<(Entity, &Thing)>().iter(&world) { | ||
| println!("{:?}", thing); | ||
| } | ||
| } |
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.