pub struct Subject<T, E> { /* private fields */ }Expand description
Implementations§
Source§impl<T, E> Subject<T, E>
impl<T, E> Subject<T, E>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Sourcepub fn notify(&self, state: &T, strategy: NotifyStrategy) -> Result<(), E>
pub fn notify(&self, state: &T, strategy: NotifyStrategy) -> Result<(), E>
通知所有观察者
向所有有效的观察者发送状态更新通知。
§参数
state: 要通知的新状态引用error_strategy: 通知策略,指定观察者失败时的行为 使用NotifyStrategy::StopOnError或NotifyStrategy::IgnoreError
§返回值
Ok(()): 所有观察者都成功处理了更新,或错误被忽略Err(E): 某个观察者处理更新时返回了错误(当使用StopOnError策略时)
§通知策略
根据指定的通知策略决定行为:
StopOnError: 立即返回第一个错误,停止通知其他观察者IgnoreError: 忽略错误,继续通知其他观察者,总是返回Ok(())
Trait Implementations§
Auto Trait Implementations§
impl<T, E> Freeze for Subject<T, E>
impl<T, E> !RefUnwindSafe for Subject<T, E>
impl<T, E> !Send for Subject<T, E>
impl<T, E> !Sync for Subject<T, E>
impl<T, E> Unpin for Subject<T, E>
impl<T, E> UnsafeUnpin for Subject<T, E>
impl<T, E> !UnwindSafe for Subject<T, E>
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