[][src]Struct vgtk::Callback

pub struct Callback<A>(_);

A callback property for sub-Components.

When a subcomponent needs to communicate with its parent, you can use a Callback to simulate a signal handler.

This is how you would declare a callback property that receives a String when something happens inside the subcomponent. The property value should be a closure which receives the String and returns a message for the parent component, of the parent component's Component::Message type. The framework will automatically take care of figuring out the callback's type signature when you mount the subcomponent.

Note that you must always wrap the callback in an Option, because the properties object is constructed using Default::default() before filling in the property values, and it needs a safe and constructable default value for the callback. More crucially, for this reason the machinery which figures out the callback's type signature is implemented for Option<Callback<_>> but not for plain Callback<_>.

struct MyComponentProperties {
    on_message: Option<Callback<String>>,
}

This is how you might provide a callback property to the above:

<@MyComponent on_message=|string| ParentMessage::StringReceived(string) />

Methods

impl<A: Debug> Callback<A>[src]

pub fn send(&self, value: A)[src]

Send a value to the callback.

Trait Implementations

impl<A> Clone for Callback<A>[src]

impl<A> Debug for Callback<A>[src]

impl<A, F: Fn(A) + 'static> From<F> for Callback<A>[src]

impl<A> PartialEq<Callback<A>> for Callback<A>[src]

Auto Trait Implementations

impl<A> !RefUnwindSafe for Callback<A>

impl<A> !Send for Callback<A>

impl<A> !Sync for Callback<A>

impl<A> Unpin for Callback<A>

impl<A> !UnwindSafe for Callback<A>

Blanket Implementations

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

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

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

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.