[][src]Struct reactive_state::Callback

pub struct Callback<State, Event>(_);

A wrapper for a callback which is notified of changes to Store State, and Events 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

impl<State, Event> Callback<State, Event>[src]

pub fn new<C: Fn(Rc<State>, Event) + 'static>(closure: C) -> Self[src]

pub fn emit(&self, state: Rc<State>, event: Event)[src]

Trait Implementations

impl<State, Event, '_> AsListener<State, Event> for &'_ Callback<State, Event>[src]

impl<State: Clone, Event: Clone> Clone for Callback<State, Event>[src]

impl<C, State, Event> From<C> for Callback<State, Event> where
    C: Fn(Rc<State>, Event) + 'static, 
[src]

impl<State, Event> From<Callback<()>> for Callback<State, Event> where
    State: 'static,
    Event: 'static, 
[src]

impl<State, Event> From<Callback<(Rc<State>, Event)>> for Callback<State, Event> where
    State: 'static,
    Event: 'static, 
[src]

impl<State, Event> From<Callback<Rc<State>>> for Callback<State, Event> where
    State: 'static,
    Event: 'static, 
[src]

Auto Trait Implementations

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Any for T where
    T: Any

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> CloneAny for T where
    T: Clone + Any

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.