Skip to main content

Signal

Struct Signal 

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

Source

pub fn new(initial: T) -> Self

分配并初始化一个响应式信号(std 下自动扩容;若槽位回收则强制递增 generation 保证类型安全)。

Source

pub fn get(self) -> T

读取信号当前值;若处于 View::render、Computed 或 Effect 上下文中,自动注册依赖订阅。

Source

pub fn get_in(self, cx: &FrameScope) -> T

在给定 FrameScope 中读取信号当前值,并显式将 cx.current_pod() 注册为订阅者。

Source

pub fn get_untracked(self) -> T

读取信号当前值但不触发依赖追踪。

Source

pub fn set(self, val: T)

写入新值,递增信号版本号,通过三色 Push-Pull 图传播脏状态并自动通知订阅视图与 Effect。

Source

pub fn set_if_changed(self, val: T) -> bool
where T: PartialEq,

当新值与旧值不相等时才写入并通知订阅者(返回 true 表示发生了实际变更)。

Source

pub fn update(self, f: impl FnOnce(&mut T))

原地修改信号值,递增版本号并自动通知所有订阅该信号的 PodId、Computed 与 Effect(闭包执行期间不持有全局表可变借用,100% 重入安全)。

Source

pub fn set_in(self, acx: &mut ActionScope<'_>, val: T)

在事件回调 ActionScope 中写入新值,并立即将所有订阅该信号的 PodId 标记到 acx.pool 脏队列中。

Source

pub fn update_in(self, acx: &mut ActionScope<'_>, f: impl FnOnce(&mut T))

在事件回调 ActionScope 中原地更新信号值,并立即将所有订阅该信号的 PodId 标记到 acx.pool 脏队列中。

Source

pub fn version(self) -> u32

获取该信号当前的单调版本号。

Source

pub fn subscribers_mask(self) -> u64

获取当前订阅了该信号的 PodId 位掩码(bit i == 1 表示 PodId(i) 依赖该信号)。

Source

pub fn dispose(self) -> bool

销毁释放该信号槽位、回收其全部下游依赖边并递增 generation(防止 ABA 悬垂引用)。

Trait Implementations§

Source§

impl<T: Copy + AddAssign<Rhs> + 'static, Rhs> AddAssign<Rhs> for Signal<T>

Source§

fn add_assign(&mut self, rhs: Rhs)

Performs the += operation. Read more
Source§

impl<T: Copy + Binary + 'static> Binary for Signal<T>

Source§

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

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

impl<T: Copy + BitOrAssign<Rhs> + 'static, Rhs> BitOrAssign<Rhs> for Signal<T>

Source§

fn bitor_assign(&mut self, rhs: Rhs)

Performs the |= operation. Read more
Source§

impl<T: Copy + BitXorAssign<Rhs> + 'static, Rhs> BitXorAssign<Rhs> for Signal<T>

Source§

fn bitxor_assign(&mut self, rhs: Rhs)

Performs the ^= operation. Read more
Source§

impl<T: Copy + 'static> Clone for Signal<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Copy + 'static> Copy for Signal<T>

Source§

impl<T: Copy + 'static> Debug for Signal<T>

Source§

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

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

impl<T: Copy + Display + 'static> Display for Signal<T>

Source§

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

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

impl<T: Copy + 'static> Eq for Signal<T>

Source§

impl<T: Copy + LowerHex + 'static> LowerHex for Signal<T>

Source§

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

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

impl<T: Copy + 'static> PartialEq for Signal<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T: Copy + PartialEq + 'static> PartialEq<T> for Signal<T>

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T: Copy + PartialOrd + 'static> PartialOrd<T> for Signal<T>

Source§

fn partial_cmp(&self, other: &T) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Copy + SubAssign<Rhs> + 'static, Rhs> SubAssign<Rhs> for Signal<T>

Source§

fn sub_assign(&mut self, rhs: Rhs)

Performs the -= operation. Read more
Source§

impl<T: Copy + UpperHex + 'static> UpperHex for Signal<T>

Source§

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

Formats the value using the given formatter. Read more

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>

§

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>

§

impl<T> UnwindSafe for Signal<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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> FluentBuilder for T

Source§

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

根据 condition 在两个修饰分支之间二选一。
Source§

fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self

当 option 为 Some(value) 时执行闭包修饰自身,否则原样返回。
Source§

fn when_none<O>( self, option: &Option<O>, then: impl FnOnce(Self) -> Self, ) -> Self

当 option 为 None 时执行闭包修饰自身,否则原样返回。
Source§

fn apply<U>(self, f: impl FnOnce(Self) -> U) -> U

通用管道映射变换(避免与 Iterator::map / Option::map 重名)。
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,