[][src]Struct bastion::message::Answer

pub struct Answer(_);

A Future returned when successfully "asking" a message using ChildRef::ask and which resolves to a Result<Msg, ()> where the Msg is the message answered by the child (see the msg! macro for more information).

Example

// The message that will be "asked"...
const ASK_MSG: &'static str = "A message containing data (ask).";
// The message the will be "answered"...
const ANSWER_MSG: &'static str = "A message containing data (answer).";

// Create a new child...
Bastion::children(|children| {
    children.with_exec(|ctx: BastionContext| {
        async move {
            // ...which will receive the message asked...
            msg! { ctx.recv().await?,
                msg: &'static str =!> {
                    assert_eq!(msg, ASK_MSG);
                    // Handle the message...

                    // ...and eventually answer to it...
                    answer!(ctx, ANSWER_MSG);
                };
                // This won't happen because this example
                // only "asks" a `&'static str`...
                _: _ => ();
            }

            Ok(())
        }
    })
}).expect("Couldn't create the children group.");

// Later, the message is "asked" to the child...
let answer: Answer = ctx.ask(&child_ref.addr(), ASK_MSG).expect("Couldn't send the message.");

// ...and the child's answer is received...
msg! { answer.await.expect("Couldn't receive the answer."),
    msg: &'static str => {
        assert_eq!(msg, ANSWER_MSG);
        // Handle the answer...
    };
    // This won't happen because this example
    // only answers a `&'static str`...
    _: _ => ();
}

Trait Implementations

impl Debug for Answer[src]

impl Future for Answer[src]

type Output = Result<SignedMessage, ()>

The type of value produced on completion.

Auto Trait Implementations

impl !RefUnwindSafe for Answer

impl Send for Answer

impl Sync for Answer

impl Unpin for Answer

impl !UnwindSafe for Answer

Blanket Implementations

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

impl<T> AsAny for T where
    T: Any
[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> FutureExt for T where
    T: Future + ?Sized
[src]

impl<T> FutureExt for T where
    T: Future + ?Sized
[src]

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

impl<T> Message for T where
    T: Any + Send + Sync + Debug
[src]

impl<T> State for T where
    T: Send + Sync + 'static, 
[src]

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<F, T, E> TryFuture for F where
    F: Future<Output = Result<T, E>> + ?Sized
[src]

type Ok = T

The type of successful values yielded by this future

type Error = E

The type of failures yielded by this future

impl<F, T, E> TryFuture for F where
    F: Future<Output = Result<T, E>> + ?Sized
[src]

type Ok = T

The type of successful values yielded by this future

type Error = E

The type of failures yielded by this future

impl<Fut> TryFutureExt for Fut where
    Fut: TryFuture + ?Sized
[src]

impl<Fut> TryFutureExt for Fut where
    Fut: TryFuture + ?Sized
[src]

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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,