pub struct WeakSignal<Args, R = (), C = DefaultCombiner, G = i32>{ /* private fields */ }Expand description
A weak reference to a signal’s slots. Useful for allowing slots to maintain a persistant reference to their owning signal without causing a memory leak.
§Example
use signals2::*;
let sig: Signal<()> = Signal::new();
let weak_sig = sig.weak();
sig.connect(move || {
// if we had captured a cloned sig here it would cause a memory leak.
// Signals maintain strong references to their slot functions, so a slot function
// should not maintain a strong reference to its own signal or else a memory leak
// will occur.
weak_sig.upgrade().unwrap().connect(|| println!("Hello, world!"));
});
sig.emit(); // prints nothing
sig.emit(); // prints "Hello, world!" once
sig.emit(); // prints "Hello, world!" twice
// etc...Implementations§
Source§impl<Args, R, C, G> WeakSignal<Args, R, C, G>
impl<Args, R, C, G> WeakSignal<Args, R, C, G>
Trait Implementations§
Source§impl<Args, R, C, G> Clone for WeakSignal<Args, R, C, G>
impl<Args, R, C, G> Clone for WeakSignal<Args, R, C, G>
Auto Trait Implementations§
impl<Args, R, C, G> Freeze for WeakSignal<Args, R, C, G>
impl<Args, R, C, G> RefUnwindSafe for WeakSignal<Args, R, C, G>
impl<Args, R, C, G> Send for WeakSignal<Args, R, C, G>
impl<Args, R, C, G> Sync for WeakSignal<Args, R, C, G>
impl<Args, R, C, G> Unpin for WeakSignal<Args, R, C, G>
impl<Args, R, C, G> UnwindSafe for WeakSignal<Args, R, C, G>
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