[−][src]Struct bastion::child_ref::ChildRef
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 is_public(&self) -> bool
[src]
Returns true if the child this ChildRef
is referencing is public,
Which means it can receive messages. private ChildRef
s
reference bastion internal children, such as the heartbeat child for example.
This function comes in handy when implementing your own dispatchers.
Example
Bastion::children(|children| { children.with_exec(|ctx| { async move { if ctx.current().is_public() { // ... } } }) }).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
children.with_exec(|ctx: BastionContext| { async move { // ...which will receive the message asked... msg! { ctx.recv().await?, msg: &'static str =!> { // Handle the message... // ...and eventually answer to it... }; // This won't happen because this example // only "asks" a `&'static str`... _: _ => (); } Ok(()) } }) }).expect("Couldn't create the children group."); 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]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
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]
T: 'static + ?Sized,
impl<T> AsAny for T where
T: Any,
[src]
T: Any,
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> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Message for T where
T: Any + Send + Sync + Debug,
[src]
T: Any + Send + Sync + Debug,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> State for T where
T: Send + Sync + 'static,
[src]
T: Send + Sync + 'static,
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 = Infallible
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<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,