Callback

Struct Callback 

Source
pub struct Callback<State, Event>(/* private fields */);
Expand description

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§

Source§

impl<State, Event> Callback<State, Event>

Source

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

Source

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

Trait Implementations§

Source§

impl<State, Event> AsListener<State, Event> for &Callback<State, Event>

Source§

fn as_listener(&self) -> Listener<State, Event>

Produce a Listener, a weak reference to this callback.
Source§

impl<State: Clone, Event: Clone> Clone for Callback<State, Event>

Source§

fn clone(&self) -> Callback<State, Event>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

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

Source§

fn from(closure: C) -> Self

Converts to this type from the input type.
Source§

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

Available on crate feature yew only.
Source§

fn from(yew_callback: Callback<()>) -> Self

Converts to this type from the input type.
Source§

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

Available on crate feature yew only.
Source§

fn from(yew_callback: Callback<(Rc<State>, Option<Event>)>) -> Self

Converts to this type from the input type.
Source§

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

Available on crate feature yew only.
Source§

fn from(yew_callback: Callback<Rc<State>>) -> Self

Converts to this type from the input type.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, V> IntoOptPropValue<V> for T
where T: IntoPropValue<Option<V>>,

Source§

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

Source§

fn into_prop_value(self) -> Option<T>

Convert self to a value of a Properties struct.
Source§

impl<T> IntoPropValue<T> for T

Source§

fn into_prop_value(self) -> T

Convert self to a value of a Properties struct.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Any for T
where T: Any,

Source§

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