-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bevy_reflect: implement Reflect for SmolStr (#8771)
# Objective To upgrade winit's dependency, it's useful to reuse SmolStr, which replaces/improves the too restrictive Key letter enums. As Input<Key> is a resource it should implement Reflect through all its fields. ## Solution Add smol_str to bevy_reflect supported types, behind a feature flag. This PR blocks winit's upgrade PR: #8745. # Current state - I'm discovering bevy_reflect, I appreciate all feedbacks, and send me your nitpicks! - Lacking more tests --------- Co-authored-by: Alice Cecile <[email protected]> Co-authored-by: Gino Valente <[email protected]>
- Loading branch information
1 parent
0080303
commit b559e9b
Showing
3 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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,28 @@ | ||
use crate::std_traits::ReflectDefault; | ||
use crate::{self as bevy_reflect}; | ||
use bevy_reflect_derive::{impl_from_reflect_value, impl_reflect_value}; | ||
|
||
impl_reflect_value!(::smol_str::SmolStr(Debug, Hash, PartialEq, Default)); | ||
impl_from_reflect_value!(::smol_str::SmolStr); | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::{FromReflect, Reflect}; | ||
use smol_str::SmolStr; | ||
|
||
#[test] | ||
fn should_partial_eq_smolstr() { | ||
let a: &dyn Reflect = &SmolStr::new("A"); | ||
let a2: &dyn Reflect = &SmolStr::new("A"); | ||
let b: &dyn Reflect = &SmolStr::new("B"); | ||
assert_eq!(Some(true), a.reflect_partial_eq(a2)); | ||
assert_eq!(Some(false), a.reflect_partial_eq(b)); | ||
} | ||
|
||
#[test] | ||
fn smolstr_should_from_reflect() { | ||
let smolstr = SmolStr::new("hello_world.rs"); | ||
let output = <SmolStr as FromReflect>::from_reflect(&smolstr); | ||
assert_eq!(Some(smolstr), output); | ||
} | ||
} |
This file contains 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