[][src]Struct bastion::child_ref::ChildRef

pub struct ChildRef { /* fields omitted */ }

A "reference" to an element of a children group, allowing to communicate with it.

Implementations

impl ChildRef[src]

pub fn id(&self) -> &BastionId[src]

Returns the identifier of the children group element this ChildRef is referencing.

Note that the children group element's identifier is reset when it is restarted.

Example

Bastion::children(|children| {
    children.with_exec(|ctx| {
        async move {
            let child_id: &BastionId = ctx.current().id();
            // ...
        }
    })
}).expect("Couldn't create the children group.");

pub fn tell_anonymously<M: Message>(&self, msg: M) -> Result<(), M>[src]

Sends a message to the child this ChildRef is referencing. This message is intended to be used outside of Bastion context when there is no way for receiver to identify message sender

This method returns () if it succeeded, or Err(msg) otherwise.

Argument

  • msg - The message to send.

Example

// The message that will be "told"...
const TELL_MSG: &'static str = "A message containing data (tell).";

// Create a new child...
Bastion::children(|children| {
    children.with_exec(|ctx: BastionContext| {
        async move {
            // ...which will receive the message "told"...
            msg! { ctx.recv().await?,
                msg: &'static str => {
                    assert_eq!(msg, TELL_MSG);
                    // Handle the message...
                };
                // This won't happen because this example
                // only "tells" a `&'static str`...
                _: _ => ();
            }

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

// Later, the message is "told" to the child...
child_ref.tell_anonymously(TELL_MSG).expect("Couldn't send the message.");

pub fn ask_anonymously<M: Message>(&self, msg: M) -> Result<Answer, M>[src]

Sends a message to the child this ChildRef is referencing, allowing it to answer. This message is intended to be used outside of Bastion context when there is no way for receiver to identify message sender

This method returns Answer if it succeeded, or Err(msg) otherwise.

Argument

  • msg - The message to send.

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 = child_ref.ask_anonymously(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`...
    _: _ => ();
}

pub fn stop(&self) -> Result<(), ()>[src]

Sends a message to the child this ChildRef is referencing to tell it to stop its execution.

This method returns () if it succeeded, or Err(()) otherwise.

Example

child_ref.stop().expect("Couldn't send the message.");

pub fn kill(&self) -> Result<(), ()>[src]

Sends a message to the child this ChildRef is referencing to tell it to suicide.

This method returns () if it succeeded, or Err(()) otherwise.

Example

child_ref.kill().expect("Couldn't send the message.");

pub fn addr(&self) -> RefAddr[src]

Returns RefAddr for the child

pub fn path(&self) -> &Arc<BastionPath>[src]

Returns the BastionPath of the child

pub fn name(&self) -> &str[src]

Return the [name] of the child

Trait Implementations

impl Clone for ChildRef[src]

impl Debug for ChildRef[src]

impl Eq for ChildRef[src]

impl Hash for ChildRef[src]

impl PartialEq<ChildRef> for ChildRef[src]

Auto Trait Implementations

impl !RefUnwindSafe for ChildRef

impl Send for ChildRef

impl Sync for ChildRef

impl Unpin for ChildRef

impl !UnwindSafe for ChildRef

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, U> Into<U> for T where
    U: From<T>, 
[src]

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

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> State for T where
    T: Send + Sync + 'static, 
[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.

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