pub struct ReflectedChange<'a> {
pub path: FieldPath,
pub change_type: ChangeType,
pub old: Option<&'a dyn PartialReflect>,
pub new: Option<&'a dyn PartialReflect>,
}Expand description
A detected change with references to the actual field values.
This struct is returned by diff_reflect and contains:
- The path to the changed field
- The type of change (Modified, Added, Removed, etc.)
- Optional references to the old and new values
§Accessing Values
The old and new fields are Option<&dyn PartialReflect>. You can:
- Check if they’re
SomeorNone(e.g.,Noneforoldif the field was added) - Downcast to concrete types using
try_downcast_ref::<T>()
§Example
use serde::Serialize;
use bevy_reflect::Reflect;
use hashmark::diff_reflect;
#[derive(Serialize, Reflect)]
struct Data { value: u32 }
let old = Data { value: 1 };
let new = Data { value: 2 };
let changes = diff_reflect(&old, &new).unwrap();
if let Some(change) = changes.first() {
if let Some(old_val) = &change.old {
if let Some(n) = old_val.try_downcast_ref::<u32>() {
println!("Old value: {}", n);
}
}
}Fields§
§path: FieldPathThe path to the changed field (e.g., “address.city”).
change_type: ChangeTypeThe type of change detected.
old: Option<&'a dyn PartialReflect>Reference to the old value, if available.
This will be None for:
- Added fields/elements
- Fields that couldn’t be resolved via reflection
new: Option<&'a dyn PartialReflect>Reference to the new value, if available.
This will be None for:
- Removed fields/elements
- Fields that couldn’t be resolved via reflection
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for ReflectedChange<'a>
impl<'a> !RefUnwindSafe for ReflectedChange<'a>
impl<'a> Send for ReflectedChange<'a>
impl<'a> Sync for ReflectedChange<'a>
impl<'a> Unpin for ReflectedChange<'a>
impl<'a> !UnwindSafe for ReflectedChange<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.