pub struct ModelStore { /* private fields */ }Expand description
Main-thread-only storage for typed models.
ModelStore is an Rc-backed container that holds model values behind type-erased entries and
provides leasing-based read/update access.
Key properties:
- Models are removed when their last strong
Model<T>handle is dropped. take_changed_modelsprovides an incremental change list for driving UI updates.- In debug/strict modes, the store tracks lease locations to surface misuse early.
Implementations§
Source§impl ModelStore
impl ModelStore
pub fn debug_created_info_for_id( &self, id: ModelId, ) -> Option<ModelCreatedDebugInfo>
pub fn debug_last_changed_info_for_id( &self, id: ModelId, ) -> Option<ModelChangedDebugInfo>
Sourcepub fn take_changed_models(&mut self) -> Vec<ModelId>
pub fn take_changed_models(&mut self) -> Vec<ModelId>
Returns and clears the list of models that were marked changed since the last call.
Dropped models are filtered out.
pub fn insert<T: Any>(&mut self, value: T) -> Model<T>
pub fn read<T: Any, R>( &self, model: &Model<T>, f: impl FnOnce(&T) -> R, ) -> Result<R, ModelUpdateError>
pub fn try_get_copied<T: Any + Copy>( &self, model: &Model<T>, ) -> Result<Option<T>, ModelUpdateError>
pub fn get_copied<T: Any + Copy>(&self, model: &Model<T>) -> Option<T>
pub fn try_get_cloned<T: Any + Clone>( &self, model: &Model<T>, ) -> Result<Option<T>, ModelUpdateError>
pub fn get_cloned<T: Any + Clone>(&self, model: &Model<T>) -> Option<T>
pub fn revision<T: Any>(&self, model: &Model<T>) -> Option<u64>
pub fn update<T: Any, R>( &mut self, model: &Model<T>, f: impl FnOnce(&mut T) -> R, ) -> Result<R, ModelUpdateError>
pub fn update_any<R>( &mut self, id: ModelId, f: impl FnOnce(&mut dyn Any) -> R, ) -> Result<R, ModelUpdateError>
pub fn notify_with_changed_at<T: Any>( &mut self, model: &Model<T>, changed_at: &'static Location<'static>, ) -> Result<(), ModelUpdateError>
pub fn notify<T: Any>( &mut self, model: &Model<T>, ) -> Result<(), ModelUpdateError>
Trait Implementations§
Source§impl Clone for ModelStore
impl Clone for ModelStore
Auto Trait Implementations§
impl Freeze for ModelStore
impl !RefUnwindSafe for ModelStore
impl !Send for ModelStore
impl !Sync for ModelStore
impl Unpin for ModelStore
impl UnsafeUnpin for ModelStore
impl !UnwindSafe for ModelStore
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