pub struct DataModel { /* private fields */ }Expand description
A reactive JSON document store with JSON Pointer support.
The data model is always a JSON object at the root. Subscribers are notified when values change at specific paths.
Implementations§
Source§impl DataModel
impl DataModel
Sourcepub fn from_value(value: Value) -> Self
pub fn from_value(value: Value) -> Self
Create from an existing JSON value. If the value is not an object, wraps it.
Sourcepub fn get(&self, pointer: &str) -> Option<&Value>
pub fn get(&self, pointer: &str) -> Option<&Value>
Get a value at an absolute JSON Pointer path.
Returns None if the path doesn’t exist.
Sourcepub fn set(&mut self, pointer: &str, value: Value)
pub fn set(&mut self, pointer: &str, value: Value)
Set a value at a JSON Pointer path with auto-vivification.
- Creates intermediate objects/arrays as needed.
- Setting
Value::Nullremoves the key. - Notifies subscribers with bubble & cascade strategy.
Sourcepub fn replace_all(&mut self, value: Value)
pub fn replace_all(&mut self, value: Value)
Replace the entire data model.
Sourcepub fn subscribe<F>(&self, callback: F) -> EventSubscription
pub fn subscribe<F>(&self, callback: F) -> EventSubscription
Subscribe to data changes.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DataModel
impl RefUnwindSafe for DataModel
impl Send for DataModel
impl Sync for DataModel
impl Unpin for DataModel
impl UnsafeUnpin for DataModel
impl UnwindSafe for DataModel
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