Enum ActorResult

Source
pub enum ActorResult<T: Actor> {
    Completed {
        actor: T,
        killed: bool,
    },
    Failed {
        actor: Option<T>,
        error: T::Error,
        phase: FailurePhase,
        killed: bool,
    },
}
Expand description

Result type returned when an actor’s lifecycle completes.

ActorResult encapsulates the final state of an actor after its lifecycle has ended, whether it completed successfully or failed. This is typically obtained when awaiting the JoinHandle returned by spawn or spawn_with_mailbox_capacity. It provides detailed information about the actor’s termination state, including:

  • Whether the actor completed successfully or failed
  • Whether the actor was killed forcefully or stopped gracefully
  • The phase in which a failure occurred (if applicable)
  • The actor instance itself (if recoverable)
  • The error that caused a failure (if applicable)

This enum is typically returned by actor supervision systems or when awaiting the completion of an actor’s task.

Variants§

§

Completed

Actor completed successfully and can be recovered.

This variant indicates that the actor finished its lifecycle without errors.

Fields

§actor: T

The successfully completed actor instance

§killed: bool

Whether the actor was killed (true) or stopped gracefully (false)

§

Failed

Actor failed during one of its lifecycle phases.

This variant indicates that the actor encountered an error during execution.

Fields

§actor: Option<T>

The actor instance (if recoverable), or None if not recoverable. This will be None specifically when the failure occurred during the on_start phase, as the actor wasn’t fully initialized.

§error: T::Error

The error that caused the failure

§phase: FailurePhase

The lifecycle phase during which the failure occurred

§killed: bool

Whether the actor was killed (true) or was attempting to stop gracefully (false)

Implementations§

Source§

impl<T: Actor> ActorResult<T>

Source

pub fn is_completed(&self) -> bool

Returns true if the actor completed successfully.

This method checks if the actor finished its lifecycle without any errors, regardless of whether it was killed or stopped normally.

Source

pub fn was_killed(&self) -> bool

Returns true if the actor was killed.

An actor is considered killed if it was terminated forcefully via the kill() method, regardless of whether it completed successfully or failed. Both ActorResult::Completed and ActorResult::Failed can have killed: true.

Source

pub fn stopped_normally(&self) -> bool

Returns true if the actor stopped normally.

An actor stopped normally if it completed successfully without being killed, typically by processing a StopGracefully message or reaching the end of its lifecycle.

Source

pub fn is_startup_failed(&self) -> bool

Returns true if the actor failed to start.

This indicates that the actor failed during the on_start lifecycle phase, which means it couldn’t initialize properly.

Source

pub fn is_runtime_failed(&self) -> bool

Returns true if the actor failed during runtime.

This indicates that the actor started successfully but encountered an error during its normal operation in the on_run lifecycle phase.

Source

pub fn is_stop_failed(&self) -> bool

Returns true if the actor failed during the stop phase.

This indicates that the actor encountered an error while trying to shut down in the on_stop lifecycle phase.

Source

pub fn actor(&self) -> Option<&T>

Returns the actor instance if available, regardless of the result type.

If the actor completed successfully, it will always return Some(actor). If the actor failed, it may return Some(actor) or None depending on when the failure occurred and if the actor instance could be recovered.

If the failure occurred during the on_start phase, this will return None since the actor was not successfully initialized.

Source

pub fn into_actor(self) -> Option<T>

Consumes the result and returns the actor instance if available.

This method is similar to actor() but it consumes the ActorResult, giving ownership of the actor to the caller if available.

Source

pub fn error(&self) -> Option<&T::Error>

Returns the error if the result represents a failure.

If the actor completed successfully, this returns None. If the actor failed, this returns Some(error) containing the error that caused the failure.

Source

pub fn into_error(self) -> Option<T::Error>

Consumes the result and returns the error if it represents a failure.

This method is similar to error() but it consumes the ActorResult, giving ownership of the error to the caller if available.

Source

pub fn is_failed(&self) -> bool

Returns true if the result represents any kind of failure.

This is the logical opposite of is_completed().

Source

pub fn has_actor(&self) -> bool

Returns true if the result contains an actor instance.

This checks if the actor instance is available, regardless of whether the actor completed successfully or failed.

Source

pub fn to_result(self) -> Result<T, T::Error>

Converts to a standard Result, preserving the actor on success

This transforms the ActorResult<T> into a Result<T, T::Error>, which is useful for integrating with Rust’s standard error handling patterns.

Trait Implementations§

Source§

impl<T: Debug + Actor> Debug for ActorResult<T>
where T::Error: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Actor> From<ActorResult<T>> for (Option<T>, Option<T::Error>)

Conversion from ActorResult to a tuple of (Option<Actor>, Option<Error>)

This allows extracting both the actor instance and error (if any) in a single operation. Useful for pattern matching and destructuring in supervision contexts.

§Example

let (maybe_actor, maybe_error) = actor_result.into();
if let Some(actor) = maybe_actor {
    // The actor is available (either completed or recovered after failure)
}
if let Some(error) = maybe_error {
    // An error occurred
}
Source§

fn from(result: ActorResult<T>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> Freeze for ActorResult<T>
where T: Freeze, <T as Actor>::Error: Freeze,

§

impl<T> RefUnwindSafe for ActorResult<T>

§

impl<T> Send for ActorResult<T>

§

impl<T> Sync for ActorResult<T>
where T: Sync, <T as Actor>::Error: Sync,

§

impl<T> Unpin for ActorResult<T>
where T: Unpin, <T as Actor>::Error: Unpin,

§

impl<T> UnwindSafe for ActorResult<T>
where T: UnwindSafe, <T as Actor>::Error: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.