diff --git a/crates/bevy_reflect/src/path/mod.rs b/crates/bevy_reflect/src/path/mod.rs index 96741b2c6a..320c414cde 100644 --- a/crates/bevy_reflect/src/path/mod.rs +++ b/crates/bevy_reflect/src/path/mod.rs @@ -127,10 +127,12 @@ impl<'a> ReflectPath<'a> for &'a str { /// Note that a leading dot (`.`) or hash (`#`) token is implied for the first item in a path, /// and may therefore be omitted. /// +/// Additionally, an empty path may be used to get the struct itself. +/// /// ### Example /// ``` /// # use bevy_reflect::{GetPath, Reflect}; -/// #[derive(Reflect)] +/// #[derive(Reflect, PartialEq, Debug)] /// struct MyStruct { /// value: u32 /// } @@ -140,6 +142,8 @@ impl<'a> ReflectPath<'a> for &'a str { /// assert_eq!(my_struct.path::(".value").unwrap(), &123); /// // Access via field index /// assert_eq!(my_struct.path::("#0").unwrap(), &123); +/// // Access self +/// assert_eq!(*my_struct.path::("").unwrap(), my_struct); /// ``` /// /// ## Tuples and Tuple Structs @@ -512,7 +516,7 @@ mod tests { use crate::*; use alloc::vec; - #[derive(Reflect)] + #[derive(Reflect, PartialEq, Debug)] struct A { w: usize, x: B, @@ -525,21 +529,21 @@ mod tests { tuple: (bool, f32), } - #[derive(Reflect)] + #[derive(Reflect, PartialEq, Debug)] struct B { foo: usize, łørđ: C, } - #[derive(Reflect)] + #[derive(Reflect, PartialEq, Debug)] struct C { mосква: f32, } - #[derive(Reflect)] + #[derive(Reflect, PartialEq, Debug)] struct D(E); - #[derive(Reflect)] + #[derive(Reflect, PartialEq, Debug)] struct E(f32, usize); #[derive(Reflect, PartialEq, Debug)] @@ -739,6 +743,7 @@ mod tests { fn reflect_path() { let mut a = a_sample(); + assert_eq!(*a.path::("").unwrap(), a); assert_eq!(*a.path::("w").unwrap(), 1); assert_eq!(*a.path::("x.foo").unwrap(), 10); assert_eq!(*a.path::("x.łørđ.mосква").unwrap(), 3.14);