pub struct Context<Msg: Message> {
pub myself: ActorRef<Msg>,
pub system: ActorSystem<Msg>,
pub persistence: Persistence<Msg>,
// some fields omitted
}
Provides context, including the actor system during actor execution.
Context
is passed to an actor's functions, such as
receive
.
Operations performed are in most cases done so from the
actor's perspective. For example, creating a child actor
using ctx.actor_of
will create the child under the current
actor within the heirarchy. In a similar manner, persistence
operations such as persist_event
use the current actor's
persistence configuration.
Since Context
is specific to an actor and its functions
it is not cloneable.
Returns the ActorRef
of the current actor.
Persists an event to the event store.
In an event sourcing environment state is maintained by
storing the events that change the state. persist_event
attempts to store the event.
State should not be modified until the event has been
successfully persisted. The event store manager notifies
the actor after each event is stored and the actor's state
can then safely be updated. The actor's apply_event
method
is called after an event is stored.
While an event is persisting it is guaranteed that no other
messages are processed until persistence is complete. I.e.,
no messages are processed between persist_event
and the
resulting apply_event
.
When an actor starts (or restarts), if pesistence is
configured the system will query the event source manager
to get all the events for the actor. Each event is then replayed,
in their original order, which effectively results in an actor
being in the latest state.
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static