pub struct Signal<T: Copy + 'static> { /* private fields */ }Expand description
NSH 风格细粒度响应式信号句柄(4 字节 Copy,含 generation 代号校验)。
支持 T: Copy + 'static(尺寸 <= 16 字节,对齐 <= 8 字节,零堆分配)。
Implementations§
Source§impl<T: Copy + 'static> Signal<T>
impl<T: Copy + 'static> Signal<T>
Sourcepub fn get_in(self, cx: &FrameScope) -> T
pub fn get_in(self, cx: &FrameScope) -> T
在给定 FrameScope 中读取信号当前值,并显式将 cx.current_pod() 注册为订阅者。
Sourcepub fn get_untracked(self) -> T
pub fn get_untracked(self) -> T
读取信号当前值但不触发依赖追踪。
Sourcepub fn set_if_changed(self, val: T) -> boolwhere
T: PartialEq,
pub fn set_if_changed(self, val: T) -> boolwhere
T: PartialEq,
当新值与旧值不相等时才写入并通知订阅者(返回 true 表示发生了实际变更)。
Sourcepub fn update(self, f: impl FnOnce(&mut T))
pub fn update(self, f: impl FnOnce(&mut T))
原地修改信号值,递增版本号并自动通知所有订阅该信号的 PodId、Computed 与 Effect(闭包执行期间不持有全局表可变借用,100% 重入安全)。
Sourcepub fn set_in(self, acx: &mut ActionScope<'_>, val: T)
pub fn set_in(self, acx: &mut ActionScope<'_>, val: T)
在事件回调 ActionScope 中写入新值,并立即将所有订阅该信号的 PodId 标记到 acx.pool 脏队列中。
Sourcepub fn update_in(self, acx: &mut ActionScope<'_>, f: impl FnOnce(&mut T))
pub fn update_in(self, acx: &mut ActionScope<'_>, f: impl FnOnce(&mut T))
在事件回调 ActionScope 中原地更新信号值,并立即将所有订阅该信号的 PodId 标记到 acx.pool 脏队列中。
Sourcepub fn subscribers_mask(self) -> u64
pub fn subscribers_mask(self) -> u64
获取当前订阅了该信号的 PodId 位掩码(bit i == 1 表示 PodId(i) 依赖该信号)。
Trait Implementations§
Source§impl<T: Copy + AddAssign<Rhs> + 'static, Rhs> AddAssign<Rhs> for Signal<T>
impl<T: Copy + AddAssign<Rhs> + 'static, Rhs> AddAssign<Rhs> for Signal<T>
Source§fn add_assign(&mut self, rhs: Rhs)
fn add_assign(&mut self, rhs: Rhs)
Performs the
+= operation. Read moreSource§impl<T: Copy + BitOrAssign<Rhs> + 'static, Rhs> BitOrAssign<Rhs> for Signal<T>
impl<T: Copy + BitOrAssign<Rhs> + 'static, Rhs> BitOrAssign<Rhs> for Signal<T>
Source§fn bitor_assign(&mut self, rhs: Rhs)
fn bitor_assign(&mut self, rhs: Rhs)
Performs the
|= operation. Read moreSource§impl<T: Copy + BitXorAssign<Rhs> + 'static, Rhs> BitXorAssign<Rhs> for Signal<T>
impl<T: Copy + BitXorAssign<Rhs> + 'static, Rhs> BitXorAssign<Rhs> for Signal<T>
Source§fn bitxor_assign(&mut self, rhs: Rhs)
fn bitxor_assign(&mut self, rhs: Rhs)
Performs the
^= operation. Read moreimpl<T: Copy + 'static> Copy for Signal<T>
impl<T: Copy + 'static> Eq for Signal<T>
Source§impl<T: Copy + PartialOrd + 'static> PartialOrd<T> for Signal<T>
impl<T: Copy + PartialOrd + 'static> PartialOrd<T> for Signal<T>
Auto Trait Implementations§
impl<T> Forget for Signal<T>
impl<T> Freeze for Signal<T>where
PhantomData<T>: Freeze,
impl<T> Move for Signal<T>
impl<T> RefUnwindSafe for Signal<T>where
PhantomData<T>: RefUnwindSafe,
impl<T> Send for Signal<T>where
PhantomData<T>: Send,
impl<T> Sync for Signal<T>where
PhantomData<T>: Sync,
impl<T> Unpin for Signal<T>where
PhantomData<T>: Unpin,
impl<T> UnsafeUnpin for Signal<T>where
PhantomData<T>: UnsafeUnpin,
impl<T> UnwindSafe for Signal<T>where
PhantomData<T>: UnwindSafe,
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<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.Source§impl<T> FluentBuilder for T
impl<T> FluentBuilder for T
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
当
condition 为 true 时执行闭包修饰自身,否则原样返回。Source§fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Self
fn when_else( self, condition: bool, then: impl FnOnce(Self) -> Self, else_fn: impl FnOnce(Self) -> Self, ) -> Self
根据
condition 在两个修饰分支之间二选一。Source§fn when_some<O>(
self,
option: Option<O>,
then: impl FnOnce(Self, O) -> Self,
) -> Self
fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self
当
option 为 Some(value) 时执行闭包修饰自身,否则原样返回。