pub struct Context<A: Actor> {
pub this: WeakActorRef<A>,
/* private fields */
}Expand description
Actor execution context providing communication and spawning capabilities.
The Context is passed to actor methods and provides access to:
- Self reference for sending messages to itself via
ctx.this.upgrade() - Child actor management via
ctx.spawn() - Actor metadata via
ctx.id() - Lifecycle control via
ctx.terminate()
§Type Parameters
A- The actor type this context belongs to
Fields§
§this: WeakActorRef<A>Weak reference to this actor instance
Implementations§
Trait Implementations§
Source§impl<A> PersistentContextExt<A> for Context<A>where
A: Actor + PersistentActor,
impl<A> PersistentContextExt<A> for Context<A>where
A: Actor + PersistentActor,
Source§impl<A> PersistentSpawnExt for Context<A>where
A: Actor,
impl<A> PersistentSpawnExt for Context<A>where
A: Actor,
Source§async fn spawn_persistent<S, Args>(
&self,
_storage: &S,
actor_id: ActorId,
args: Args,
) -> Result<ActorRef<Args::Actor>, PersistenceError>
async fn spawn_persistent<S, Args>( &self, _storage: &S, actor_id: ActorId, args: Args, ) -> Result<ActorRef<Args::Actor>, PersistenceError>
Spawn an actor with persistence support. Read more
Source§async fn respawn<S, B>(
&self,
storage: &S,
actor_id: ActorId,
runtime_args: B::RuntimeArgs,
) -> Result<ActorRef<B>, PersistenceError>
async fn respawn<S, B>( &self, storage: &S, actor_id: ActorId, runtime_args: B::RuntimeArgs, ) -> Result<ActorRef<B>, PersistenceError>
Since it coerce the given Id to actor, it is callers’ responsibility to ensure no more than one actor is spawned with the same ID.Failure to do so will not result error immediately, but latened undefined behavior.It does not invoke
PersistentContextExt::save_snapshot automatically, it should be specified in ActorArgs::initialize if needed. Read moreSource§async fn respawn_or<S, Args>(
&self,
storage: &S,
actor_id: ActorId,
runtime_args: impl FnOnce() -> <<Args as ActorArgs>::Actor as PersistentActor>::RuntimeArgs + Send,
default_args: impl FnOnce() -> Args + Send,
) -> Result<ActorRef<Args::Actor>, PersistenceError>
async fn respawn_or<S, Args>( &self, storage: &S, actor_id: ActorId, runtime_args: impl FnOnce() -> <<Args as ActorArgs>::Actor as PersistentActor>::RuntimeArgs + Send, default_args: impl FnOnce() -> Args + Send, ) -> Result<ActorRef<Args::Actor>, PersistenceError>
Since it coerce the given Id to actor, it is callers’ responsibility to ensure no more than one actor is spawned with the same ID.Failure to do so will not result error immediately, but latened undefined behavior.It does not invoke
PersistentContextExt::save_snapshot automatically, it should be specified in ActorArgs::initialize if needed. Read moreAuto Trait Implementations§
impl<A> Freeze for Context<A>
impl<A> RefUnwindSafe for Context<A>
impl<A> Send for Context<A>
impl<A> Sync for Context<A>
impl<A> Unpin for Context<A>
impl<A> UnsafeUnpin for Context<A>
impl<A> UnwindSafe for Context<A>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more