Skip to main content

Model

Struct Model 

Source
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 to Model<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>

Source

pub fn id(&self) -> ModelId

Source

pub fn downgrade(&self) -> WeakModel<T>

Returns a weak handle that can be upgraded if the model is still alive.

Source

pub fn read<H, R>( &self, host: &mut H, f: impl FnOnce(&mut H, &T) -> R, ) -> Result<R, ModelUpdateError>
where H: ModelHost, T: Any,

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).

Source

pub fn update<H, R>( &self, host: &mut H, f: impl FnOnce(&mut T, &mut ModelCx<'_, H>) -> R, ) -> Result<R, ModelUpdateError>
where H: ModelHost, T: Any,

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.

Source

pub fn revision<H>(&self, host: &H) -> Option<u64>
where H: ModelHost, T: Any,

Source

pub fn notify<H>(&self, host: &mut H) -> Result<(), ModelUpdateError>
where H: ModelHost, T: Any,

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.

Source

pub fn read_ref<H, R>( &self, host: &H, f: impl FnOnce(&T) -> R, ) -> Result<R, ModelUpdateError>
where H: ModelHost, T: Any,

Trait Implementations§

Source§

impl<T> Clone for Model<T>

Source§

fn clone(&self) -> Model<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Model<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for Model<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> Hash for Model<T>

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> IntoFormValueModel<T> for &Model<T>

Source§

impl<T> IntoFormValueModel<T> for Model<T>

Source§

impl IntoTableStateModel for &Model<TableState>

Source§

impl IntoTableStateModel for Model<TableState>

Source§

impl<T> PartialEq for Model<T>

Source§

fn eq(&self, other: &Model<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Any> TrackedModelExt<T> for Model<T>

Source§

fn watch_in<'cx, 'a, H: UiHost>( &self, cx: &'cx mut ElementContext<'a, H>, ) -> WatchedModel<'cx, '_, 'a, H, T>

Source§

fn paint_in<'cx, 'a, H: UiHost>( &self, cx: &'cx mut ElementContext<'a, H>, ) -> WatchedModel<'cx, '_, 'a, H, T>

Source§

fn layout_in<'cx, 'a, H: UiHost>( &self, cx: &'cx mut ElementContext<'a, H>, ) -> WatchedModel<'cx, '_, 'a, H, T>

Source§

fn hit_test_in<'cx, 'a, H: UiHost>( &self, cx: &'cx mut ElementContext<'a, H>, ) -> WatchedModel<'cx, '_, 'a, H, T>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UiElementA11yExt for T

Source§

fn a11y(self, decoration: SemanticsDecoration) -> UiElementWithA11y<Self>

Source§

fn a11y_role(self, role: SemanticsRole) -> UiElementWithA11y<Self>

Source§

fn a11y_label(self, label: impl Into<Arc<str>>) -> UiElementWithA11y<Self>

Source§

fn a11y_value(self, value: impl Into<Arc<str>>) -> UiElementWithA11y<Self>

Source§

fn a11y_disabled(self, disabled: bool) -> UiElementWithA11y<Self>

Source§

fn a11y_selected(self, selected: bool) -> UiElementWithA11y<Self>

Source§

fn a11y_expanded(self, expanded: bool) -> UiElementWithA11y<Self>

Source§

fn a11y_checked(self, checked: Option<bool>) -> UiElementWithA11y<Self>

Source§

impl<T> UiElementKeyContextExt for T

Source§

fn key_context( self, key_context: impl Into<Arc<str>>, ) -> UiElementWithKeyContext<Self>

Source§

impl<T> UiElementTestIdExt for T

Source§

fn test_id(self, id: impl Into<Arc<str>>) -> UiElementWithTestId<Self>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more