Struct elfo_core::Context[][src]

pub struct Context<C = (), K = Singleton, S = ()> { /* fields omitted */ }
Expand description

An actor execution context.

Implementations

Returns the actor’s address.

Returns the current group’s address.

Returns the actual config.

Returns the actor’s key.

Transforms the context to another one with the provided source.

Updates the actor’s status.

ctx.set_status(ActorStatus::ALARMING.with_details("something wrong"));

Closes the mailbox, that leads to returning None from recv() and try_recv() after handling all available messages in the mailbox.

Returns true if the mailbox has just been closed.

Sends a message using the routing system.

Returns Err if the message hasn’t reached any mailboxes.

Example
// Fire and forget.
let _ = ctx.send(SomethingHappened).await;

// Fire or fail.
ctx.send(SomethingHappened).await?;

// Fire or log.
if let Some(err) = ctx.send(SomethingHappened).await {
    warn!("...", error = err);
}

Returns a request builder.

Example
// Request and wait for a response.
let response = ctx.request(SomeCommand).resolve().await?;

// Request and wait for all responses.
for result in ctx.request(SomeCommand).all().resolve().await {
    // ...
}

Sends a message to the specified recipient.

Returns Err if the message hasn’t reached any mailboxes.

Example
// Fire and forget.
let _ = ctx.send_to(addr, SomethingHappened).await;

// Fire or fail.
ctx.send_to(addr, SomethingHappened).await?;

// Fire or log.
if let Some(err) = ctx.send_to(addr, SomethingHappened).await {
    warn!("...", error = err);
}

Tries to send a message to the specified recipient.

Returns Err if the message hasn’t reached mailboxes or they are full.

Example
// Fire and forget.
let _ = ctx.send(SomethingHappened).await;

// Fire or fail.
ctx.send(SomethingHappened).await?;

// Fire or log.
if let Some(err) = ctx.send(SomethingHappened).await {
    warn!("...", error = err);
}

Responds to the requester with the provided response.

The token can be used only once.

msg!(match envelope {
    (SomeRequest, token) => {
        ctx.respond(token, SomeResponse);
    }
})

Receives the next envelope.

Panics

If the method is called again after returning None.

Examples
while let Some(envelope) = ctx.recv().await {
    msg!(match envelope {
        SomethingHappened => /* ... */,
    })
}

Receives the next envelope without waiting.

Panics

If the method is called again after returning Err(TryRecvError::Closed).

Examples
// Iterate over all available messages.
while let Ok(envelope) = ctx.try_recv() {
    msg!(match envelope {
        SomethingHappened => /* ... */,
    })
}

Used to get the typed config from ValidateConfig.

msg!(match envelope {
    (ValidateConfig { config, .. }, token) => {
        let new_config = ctx.unpack_config(&config);
        ctx.respond(token, Err("oops".into()));
    }
})

Produces a new context that can be used for sending messages only.

Pruned contexts are likely to be removed in favor of Output.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more