Skip to main content

Signal

Struct Signal 

Source
pub struct Signal<T> { /* private fields */ }
Expand description

细粒度响应式值

Implementations§

Source§

impl<T: Clone + 'static> Signal<LoadState<T>>

Source

pub fn begin_load(&self) -> LoadState<T>

开始取数(自动区分首载 / 刷新),返回新状态便于调用方判断。

Source

pub fn finish_load(&self, value: T)

取数成功。

Source

pub fn fail_load(&self, message: impl Into<Rc<str>>)

取数失败(保留旧数据)。

Source§

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

Source

pub fn new(initial: T) -> Self

Source

pub fn id(&self) -> SignalId

Source

pub fn get(&self) -> T

读取值,并把当前 subscriber 加入依赖集合

Source

pub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R

借用值执行闭包(不 clone),同时按 get 语义登记订阅。

大值(Vec/字符串/Store 列表)只读计算时应优先用它,避免每次 build 复制。

Source

pub fn peek(&self) -> T

读取值但不建立订阅。

宿主/应用级读取会标记为 peeked:该 Signal 变化时触发全树 rebuild (因为宿主可能在 build 前半段用 peek 生成了 widget props)。

Source

pub fn peek_with<R>(&self, f: impl FnOnce(&T) -> R) -> R

peek 的零拷贝版本:借用值执行闭包,并标记宿主级读取。

Source

pub fn peek_silent(&self) -> T

读取值但不建立订阅、也不标记宿主全树重建。

仅用于 Debug/统计等纯展示路径;UI build 需要使用 peek()(宿主级读取) 或 get()(组件 build 内订阅)。

Source

pub fn peek_silent_with<R>(&self, f: impl FnOnce(&T) -> R) -> R

peek_silent 的零拷贝版本(Debug/统计等纯展示路径)。

Source

pub fn set(&self, value: T)

直接设值并触发 dirty

Source

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

仅当值真正变化时设值并通知;返回是否发生变化。

高频路径(hover/滚动/主题同值写回)用它跳过无意义的 dirty 传播。

Source

pub fn update_if_changed(&self, f: impl FnOnce(&mut T)) -> bool
where T: PartialEq,

仅当 f 产生的新值与原值不同时通知;返回是否发生变化。

Source

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

修改值并触发 dirty

Source

pub fn subscriber_count(&self) -> usize

当前订阅者数量(测试用)

Trait Implementations§

Source§

impl<T: '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: 'static> Debug 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> !RefUnwindSafe for Signal<T>

§

impl<T> !Send for Signal<T>

§

impl<T> !Sync for Signal<T>

§

impl<T> !UnwindSafe for Signal<T>

§

impl<T> Forget for Signal<T>

§

impl<T> Freeze for Signal<T>
where Rc<RefCell<SignalInner<T>>>: Freeze,

§

impl<T> Move for Signal<T>

§

impl<T> Unpin for Signal<T>
where Rc<RefCell<SignalInner<T>>>: Unpin,

§

impl<T> UnsafeUnpin for Signal<T>
where Rc<RefCell<SignalInner<T>>>: UnsafeUnpin,

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<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<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> 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, 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.