pub struct StoredValue<T> { /* private fields */ }Expand description
存值:不需要响应的数据(Rc 包着的服务、配置、缓存)放在运行时里,换一个 Copy 的句柄。
和 Signal 一样归创建时的作用域、句柄能随意被闭包捕获,所以不用为每个闭包先克隆一份;
不同的是读不订阅、写不通知,值变了界面也不会更新(要更新就用信号)。作用域释放后再读会 panic,
确实可能已经释放时用 StoredValue::try_with。
Implementations§
Source§impl<T> StoredValue<T>where
T: 'static,
impl<T> StoredValue<T>where
T: 'static,
Sourcepub fn new(value: T) -> StoredValue<T>
pub fn new(value: T) -> StoredValue<T>
创建存值,归当前作用域所有
Sourcepub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
pub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
借用读取(不订阅)。闭包里可以 StoredValue::set:手里的还是读开始时的值
Sourcepub fn try_with<R>(&self, f: impl FnOnce(&T) -> R) -> Option<R>
pub fn try_with<R>(&self, f: impl FnOnce(&T) -> R) -> Option<R>
和 StoredValue::with 一样借用读取,已经释放时是 None
Sourcepub fn update(&self, f: impl FnOnce(&mut T))
pub fn update(&self, f: impl FnOnce(&mut T))
原地修改(不通知谁)。已经释放时什么都不做;正在读它(在它自己的 StoredValue::with 闭包里)时 panic
Trait Implementations§
Source§impl<T> Clone for StoredValue<T>
impl<T> Clone for StoredValue<T>
Source§fn clone(&self) -> StoredValue<T>
fn clone(&self) -> StoredValue<T>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl<T> Copy for StoredValue<T>
Source§impl<T> Debug for StoredValue<T>
impl<T> Debug for StoredValue<T>
impl<T> Eq for StoredValue<T>
Auto Trait Implementations§
impl<T> !Send for StoredValue<T>
impl<T> !Sync for StoredValue<T>
impl<T> Forget for StoredValue<T>
impl<T> Freeze for StoredValue<T>
impl<T> RefUnwindSafe for StoredValue<T>
impl<T> Unpin for StoredValue<T>
impl<T> UnsafeUnpin for StoredValue<T>
impl<T> UnwindSafe for StoredValue<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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.