pub struct Signal<T: ?Sized>(/* private fields */);
Expand description
A Signal
that can be written to.
This is a wrapper around ReadSignal
.
Signals are used to store state that can be read from and written to.
Using ReadSignal::get()
and Signal::set()
. Getting the value of a signal
will track the signal in the currently running effect
, and setting the
value of a signal will trigger all the callbacks and effects, that are subscribed to
the signal.
§Example
// create a new signal
let signal = cx.signal(0);
// create a new effect
cx.effect(|| {
// this will be called when it's created
// and every time the signal is set
println!("signal value: {}", signal.get());
});
// set the signal to 1
// this will trigger the effect
signal.set(1);
Implementations§
Methods from Deref<Target = ReadSignal<T>>§
Sourcepub fn emitter(&self) -> &CallbackEmitter
pub fn emitter(&self) -> &CallbackEmitter
Gets the CallbackEmitter
for this ReadSignal
.
Sourcepub fn get(&self) -> Rc<T>
pub fn get(&self) -> Rc<T>
Gets the current value of self
.
This will track self
in the currently running effect
.
Sourcepub fn get_untracked(&self) -> Rc<T>
pub fn get_untracked(&self) -> Rc<T>
Gets the current value of self
without tracking it.
Sourcepub fn cloned(&self) -> T
pub fn cloned(&self) -> T
Returns a clone of the current value of self
.
This will track self
in the currently running effect
.
Sourcepub fn cloned_untracked(&self) -> T
pub fn cloned_untracked(&self) -> T
Returns a clone of the current value of self
without tracking it.
Sourcepub fn copied_untracked(&self) -> T
pub fn copied_untracked(&self) -> T
Returns a copy to the current value of self
.
Trait Implementations§
Source§impl<T: Ord + ?Sized> Ord for Signal<T>
impl<T: Ord + ?Sized> Ord for Signal<T>
Source§impl<T: PartialOrd + ?Sized> PartialOrd<T> for Signal<T>
impl<T: PartialOrd + ?Sized> PartialOrd<T> for Signal<T>
Source§impl<T: PartialOrd + ?Sized> PartialOrd for Signal<T>
impl<T: PartialOrd + ?Sized> PartialOrd for Signal<T>
impl<T: Eq + ?Sized> Eq for Signal<T>
Auto Trait Implementations§
impl<T> !Freeze for Signal<T>
impl<T> !RefUnwindSafe for Signal<T>
impl<T> !Send for Signal<T>
impl<T> !Sync for Signal<T>
impl<T> Unpin for Signal<T>where
T: ?Sized,
impl<T> !UnwindSafe for Signal<T>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.Source§impl<T> Styleable<T> for T
impl<T> Styleable<T> for T
Source§fn styled(self) -> Styled<T>
fn styled(self) -> Styled<T>
self
into a Styled<Self>
value.