[−][src]Struct bastion::children::ChildRef
A "reference" to an element of a children group, allowing to communicate with it.
Methods
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<M: Message>(&self, msg: M) -> Result<(), M>
[src]
Sends a message to the child this ChildRef
is referencing.
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(TELL_MSG).expect("Couldn't send the message.");
pub fn ask<M: Message>(&self, msg: M) -> Result<Answer, M>
[src]
Sends a message to the child this ChildRef
is referencing,
allowing it to answer.
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!(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(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.");
Trait Implementations
impl Clone for ChildRef
[src]
impl Eq for ChildRef
[src]
impl PartialEq<ChildRef> for ChildRef
[src]
impl Debug for ChildRef
[src]
Auto Trait Implementations
impl Send for ChildRef
impl Sync for ChildRef
impl Unpin for ChildRef
impl !UnwindSafe for ChildRef
impl !RefUnwindSafe for ChildRef
Blanket Implementations
impl<T> Message for T where
T: Any + Send + Sync + Debug,
[src]
T: Any + Send + Sync + Debug,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,