pub struct Callback<State, Event>(/* private fields */);
Expand description
A wrapper for a callback which is notified of changes to
Store State
, and Event
s produced by the store.
§Example
The following example makes use of the AsListener
trait implementation for Callback
which allows it to be used in
Store::subscribe(). The
AsListener trait creates a weak reference to this
callback in a Listener, which is given to the
Store. When the callback is dropped, the listener will be
removed from the store.
use reactive_state::Callback;
let callback = Callback::new(|_state, _event| {
println!("Callback invoked");
});
store.subscribe(&callback);
§Optional Features
If the "yew"
crate feature is enabled, a number of From
implementations are available to convert yew
callbacks into
this:
From<yew::Callback<Rc<State>>>
From<yew::Callback<(Rc<State>, Event)>>
From<yew::Callback<()>>
Implementations§
Trait Implementations§
Source§impl<State, Event> AsListener<State, Event> for &Callback<State, Event>
impl<State, Event> AsListener<State, Event> for &Callback<State, Event>
Source§fn as_listener(&self) -> Listener<State, Event>
fn as_listener(&self) -> Listener<State, Event>
Produce a Listener, a weak reference to this callback.
Source§impl<State, Event> From<Callback<()>> for Callback<State, Event>where
State: 'static,
Event: 'static,
Available on crate feature yew
only.
impl<State, Event> From<Callback<()>> for Callback<State, Event>where
State: 'static,
Event: 'static,
Available on crate feature
yew
only.Auto Trait Implementations§
impl<State, Event> Freeze for Callback<State, Event>
impl<State, Event> !RefUnwindSafe for Callback<State, Event>
impl<State, Event> !Send for Callback<State, Event>
impl<State, Event> !Sync for Callback<State, Event>
impl<State, Event> Unpin for Callback<State, Event>
impl<State, Event> !UnwindSafe for Callback<State, Event>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, V> IntoOptPropValue<V> for Twhere
T: IntoPropValue<Option<V>>,
impl<T, V> IntoOptPropValue<V> for Twhere
T: IntoPropValue<Option<V>>,
Source§fn into_opt_prop_value(self) -> Option<V>
fn into_opt_prop_value(self) -> Option<V>
Convert
self
to an optional value of a Properties
struct.Source§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
Source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
Convert
self
to a value of a Properties
struct.Source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
Source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
Convert
self
to a value of a Properties
struct.