Expand description
Types and traits for observing mutations to data structures.
§How Observers Work
Observers are types that implement DerefMut to the target type being
observed. When any method requiring &mut self is called, it triggers the
DerefMut hook where change tracking occurs. Additionally, for specific
methods like String::push_str and Vec::push, observers provide specialized
implementations for more precise tracking.
For types that already implement Deref (like Box<T>), implementing
observers is more challenging. If type A dereferences to B, and we have corresponding
observers A' and B', where should A' deref to?
- If
A'→A→B: Changes on B cannot be precisely tracked (because noB'in the dereference chain) - If
A'→B'→B: Properties and methods on A become inaccessible (because noAin the dereference chain)
To solve this, we use a Pointer type to create the dereference chain: A' → B' →
Pointer<A> → A → B. This allows tracking changes on both A and B.
Structs§
- Default
Spec - Default observation specification.
- Snapshot
Spec - Snapshot-based observation specification.
Traits§
- Observe
- A trait for types that can be observed for mutations.
- Observe
Ext - Extension trait providing ergonomic methods for types implementing
Observe. - Observer
- A trait for observer types that wrap and track mutations to values.
- RefObserve
- A trait for types whose references can be observed for mutations.
- Serialize
Observer - Trait for observers that can serialize their recorded mutations.
- Serialize
Observer Ext - Extension trait providing ergonomic methods for
SerializeObserver.