[][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 the Default implementation for Callback constructs an empty callback, which does nothing and allocates nothing. This is the desired behaviour when using a callback as a Component property: if the user doesn't specify a callback explicitly, there shouldn't be a callback.

struct MyComponentProperties {
    on_message: Callback<String>,
}

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

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

Methods

impl<A> Callback<A>[src]

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

Send a value to the callback.

If the callback is empty, this has no effect.

pub fn is_empty(&self) -> bool[src]

Test whether a callback is empty.

Trait Implementations

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

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

impl<A> Default 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.