pub struct Effect { /* private fields */ }Expand description
A side effect that runs when its dependencies change
Effects automatically track which signals they read and re-run when any of those signals change. This is the core of the reactive system.
§Example
ⓘ
let count = signal(0);
// This effect automatically tracks `count` as a dependency
let _effect = Effect::new(move || {
println!("Count: {}", count.get());
});
count.set(1); // Effect re-runs, prints "Count: 1"
count.set(2); // Effect re-runs, prints "Count: 2"§Thread Safety
Effect closures must be Send + Sync since Signals are now thread-safe.
This is automatically satisfied when capturing Signals.
Implementations§
Source§impl Effect
impl Effect
Sourcepub fn new(f: impl Fn() + Send + Sync + 'static) -> Self
pub fn new(f: impl Fn() + Send + Sync + 'static) -> Self
Create a new effect that runs immediately with automatic dependency tracking
Sourcepub fn lazy(f: impl Fn() + Send + Sync + 'static) -> Self
pub fn lazy(f: impl Fn() + Send + Sync + 'static) -> Self
Create an effect without running immediately (lazy initialization)
Sourcepub fn resume(&self)
pub fn resume(&self)
Resume the effect (will need to be run manually to re-establish dependencies)
Sourcepub fn id(&self) -> SubscriberId
pub fn id(&self) -> SubscriberId
Get the effect’s unique ID
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Effect
impl !RefUnwindSafe for Effect
impl Send for Effect
impl Sync for Effect
impl Unpin for Effect
impl UnsafeUnpin for Effect
impl !UnwindSafe for Effect
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