pub struct Model<T> { /* private fields */ }Expand description
A reference-counted handle to a typed model stored in a ModelStore.
This is intentionally gpui-like (Entity<T>):
Model<T>is a strong handle (cloning increments a per-model strong count).WeakModel<T>can be upgraded back toModel<T>if the model is still alive.- When the last strong handle is dropped, the model is removed from the store.
Implementations§
Source§impl<T> Model<T>
impl<T> Model<T>
pub fn id(&self) -> ModelId
Sourcepub fn downgrade(&self) -> WeakModel<T>
pub fn downgrade(&self) -> WeakModel<T>
Returns a weak handle that can be upgraded if the model is still alive.
Sourcepub fn read<H, R>(
&self,
host: &mut H,
f: impl FnOnce(&mut H, &T) -> R,
) -> Result<R, ModelUpdateError>
pub fn read<H, R>( &self, host: &mut H, f: impl FnOnce(&mut H, &T) -> R, ) -> Result<R, ModelUpdateError>
Reads the model value using the host’s read path.
This acquires a temporary lease and ensures the lease is released even if the closure
panics (when panic=unwind).
Sourcepub fn update<H, R>(
&self,
host: &mut H,
f: impl FnOnce(&mut T, &mut ModelCx<'_, H>) -> R,
) -> Result<R, ModelUpdateError>
pub fn update<H, R>( &self, host: &mut H, f: impl FnOnce(&mut T, &mut ModelCx<'_, H>) -> R, ) -> Result<R, ModelUpdateError>
Updates the model value using the host’s update path.
The provided ModelCx exposes the host while the lease is active, allowing updates that
coordinate multiple models.
pub fn revision<H>(&self, host: &H) -> Option<u64>
Sourcepub fn notify<H>(&self, host: &mut H) -> Result<(), ModelUpdateError>
pub fn notify<H>(&self, host: &mut H) -> Result<(), ModelUpdateError>
Marks the model as changed without mutating its value.
This is useful for “derived invalidation” cases where the model’s internal state changes via interior mutability or external resources and you still want observers to re-run.
pub fn read_ref<H, R>( &self, host: &H, f: impl FnOnce(&T) -> R, ) -> Result<R, ModelUpdateError>
Trait Implementations§
Source§impl<T> IntoFormValueModel<T> for &Model<T>
impl<T> IntoFormValueModel<T> for &Model<T>
fn into_form_value_model(self) -> Model<T>
Source§impl<T> IntoFormValueModel<T> for Model<T>
impl<T> IntoFormValueModel<T> for Model<T>
fn into_form_value_model(self) -> Model<T>
Source§impl IntoTableStateModel for &Model<TableState>
impl IntoTableStateModel for &Model<TableState>
fn into_table_state_model(self) -> Model<TableState>
Source§impl IntoTableStateModel for Model<TableState>
impl IntoTableStateModel for Model<TableState>
fn into_table_state_model(self) -> Model<TableState>
Source§impl<T: Any> TrackedModelExt<T> for Model<T>
impl<T: Any> TrackedModelExt<T> for Model<T>
fn watch_in<'cx, 'a, H: UiHost>( &self, cx: &'cx mut ElementContext<'a, H>, ) -> WatchedModel<'cx, '_, 'a, H, T>
fn paint_in<'cx, 'a, H: UiHost>( &self, cx: &'cx mut ElementContext<'a, H>, ) -> WatchedModel<'cx, '_, 'a, H, T>
fn layout_in<'cx, 'a, H: UiHost>( &self, cx: &'cx mut ElementContext<'a, H>, ) -> WatchedModel<'cx, '_, 'a, H, T>
fn hit_test_in<'cx, 'a, H: UiHost>( &self, cx: &'cx mut ElementContext<'a, H>, ) -> WatchedModel<'cx, '_, 'a, H, T>
impl<T> Eq for Model<T>
Auto Trait Implementations§
impl<T> Freeze for Model<T>
impl<T> !RefUnwindSafe for Model<T>
impl<T> !Send for Model<T>
impl<T> !Sync for Model<T>
impl<T> Unpin for Model<T>
impl<T> UnsafeUnpin for Model<T>
impl<T> !UnwindSafe for Model<T>
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