pub struct WeakModel<T> { /* private fields */ }
Implementations§
source§impl<T: 'static> WeakModel<T>
impl<T: 'static> WeakModel<T>
sourcepub fn upgrade(&self) -> Option<Model<T>>
pub fn upgrade(&self) -> Option<Model<T>>
Upgrade this weak model reference into a strong model reference
sourcepub fn update<C, R>(
&self,
cx: &mut C,
update: impl FnOnce(&mut T, &mut ModelContext<'_, T>) -> R
) -> Result<R>where
C: Context,
Result<C::Result<R>>: Flatten<R>,
pub fn update<C, R>( &self, cx: &mut C, update: impl FnOnce(&mut T, &mut ModelContext<'_, T>) -> R ) -> Result<R>where C: Context, Result<C::Result<R>>: Flatten<R>,
Update the entity referenced by this model with the given function if the referenced entity still exists. Returns an error if the entity has been released.
The update function receives a context appropriate for its environment.
When updating in an AppContext
, it receives a ModelContext
.
When updating an a WindowContext
, it receives a ViewContext
.
Methods from Deref<Target = AnyWeakModel>§
pub fn entity_id(&self) -> EntityId
pub fn is_upgradable(&self) -> bool
pub fn upgrade(&self) -> Option<AnyModel>
Trait Implementations§
source§impl<T> From<WeakModel<T>> for AnyWeakModel
impl<T> From<WeakModel<T>> for AnyWeakModel
source§impl<T> PartialEq<Model<T>> for WeakModel<T>
impl<T> PartialEq<Model<T>> for WeakModel<T>
source§impl<T> PartialEq<WeakModel<T>> for Model<T>
impl<T> PartialEq<WeakModel<T>> for Model<T>
source§impl<T> PartialEq<WeakModel<T>> for WeakModel<T>
impl<T> PartialEq<WeakModel<T>> for WeakModel<T>
impl<T> Eq for WeakModel<T>
impl<T> Send for WeakModel<T>
impl<T> Sync for WeakModel<T>
Auto Trait Implementations§
impl<T> !RefUnwindSafe for WeakModel<T>
impl<T> Unpin for WeakModel<T>where T: Unpin,
impl<T> !UnwindSafe for WeakModel<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
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.