Skip to main content

Outcome

Enum Outcome 

Source
pub enum Outcome<T, E> {
    Ok(T),
    Err(E),
    Cancelled(CancelReason),
    Panicked(PanicPayload),
}
Expand description

The four-valued outcome of a concurrent operation.

Forms a severity lattice where worse outcomes dominate: Ok < Err < Cancelled < Panicked

Variants§

§

Ok(T)

Success with a value.

§

Err(E)

Application-level error.

§

Cancelled(CancelReason)

The operation was cancelled.

§

Panicked(PanicPayload)

The operation panicked.

Implementations§

Source§

impl<T> Outcome<T, AtpError>

Convenience constructors for ATP outcomes.

Source

pub fn transport_error(error: TransportError) -> Outcome<T, AtpError>

Create a transport error outcome.

Source

pub fn protocol_error(error: ProtocolError) -> Outcome<T, AtpError>

Create a protocol error outcome.

Source

pub fn auth_error(error: AuthError) -> Outcome<T, AtpError>

Create an auth error outcome.

Source

pub fn disk_error(error: DiskError) -> Outcome<T, AtpError>

Create a disk error outcome.

Source

pub fn atp_cancelled(reason: AtpCancelReason) -> Outcome<T, AtpError>

Create an ATP cancellation outcome.

Source§

impl<T, E> Outcome<T, E>

Source

pub const fn ok(value: T) -> Outcome<T, E>

Creates a successful outcome with the given value.

§Examples
use asupersync::Outcome;

let outcome: Outcome<i32, &str> = Outcome::ok(42);
assert!(outcome.is_ok());
assert_eq!(outcome.unwrap(), 42);
Source

pub const fn err(error: E) -> Outcome<T, E>

Creates an error outcome with the given error.

§Examples
use asupersync::Outcome;

let outcome: Outcome<i32, &str> = Outcome::err("not found");
assert!(outcome.is_err());
Source

pub const fn cancelled(reason: CancelReason) -> Outcome<T, E>

Creates a cancelled outcome with the given reason.

§Examples
use asupersync::{Outcome, CancelReason};

let outcome: Outcome<i32, &str> = Outcome::cancelled(CancelReason::timeout());
assert!(outcome.is_cancelled());
Source

pub const fn panicked(payload: PanicPayload) -> Outcome<T, E>

Creates a panicked outcome with the given payload.

§Examples
use asupersync::{Outcome, PanicPayload};

let outcome: Outcome<i32, &str> = Outcome::panicked(PanicPayload::new("oops"));
assert!(outcome.is_panicked());
Source

pub const fn severity(&self) -> Severity

Returns the severity level of this outcome.

The severity levels are ordered: Ok < Err < Cancelled < Panicked. This is useful for aggregation where the worst outcome should win.

§Examples
use asupersync::{Outcome, Severity, CancelReason};

let ok: Outcome<i32, &str> = Outcome::ok(42);
let err: Outcome<i32, &str> = Outcome::err("oops");
let cancelled: Outcome<i32, &str> = Outcome::cancelled(CancelReason::timeout());

assert_eq!(ok.severity(), Severity::Ok);
assert_eq!(err.severity(), Severity::Err);
assert_eq!(cancelled.severity(), Severity::Cancelled);
assert!(ok.severity() < err.severity());
Source

pub const fn severity_u8(&self) -> u8

Returns the numeric severity level (0 = Ok, 3 = Panicked).

Prefer severity() for type-safe comparisons.

Source

pub const fn is_terminal(&self) -> bool

Returns true if this is a terminal outcome (any non-pending state).

All Outcome variants are terminal states.

Source

pub const fn is_ok(&self) -> bool

Returns true if this outcome is Ok.

§Examples
use asupersync::Outcome;

let ok: Outcome<i32, &str> = Outcome::ok(42);
let err: Outcome<i32, &str> = Outcome::err("oops");

assert!(ok.is_ok());
assert!(!err.is_ok());
Source

pub const fn is_err(&self) -> bool

Returns true if this outcome is Err.

§Examples
use asupersync::Outcome;

let err: Outcome<i32, &str> = Outcome::err("oops");
assert!(err.is_err());
Source

pub const fn is_cancelled(&self) -> bool

Returns true if this outcome is Cancelled.

§Examples
use asupersync::{Outcome, CancelReason};

let cancelled: Outcome<i32, &str> = Outcome::cancelled(CancelReason::timeout());
assert!(cancelled.is_cancelled());
Source

pub const fn is_panicked(&self) -> bool

Returns true if this outcome is Panicked.

§Examples
use asupersync::{Outcome, PanicPayload};

let panicked: Outcome<i32, &str> = Outcome::panicked(PanicPayload::new("oops"));
assert!(panicked.is_panicked());
Source

pub fn into_result(self) -> Result<T, OutcomeError<E>>

Converts this outcome to a standard Result, with cancellation and panic as errors.

This is useful when interfacing with code that expects Result.

Source

pub fn map<U, F>(self, f: F) -> Outcome<U, E>
where F: FnOnce(T) -> U,

Maps the success value using the provided function.

Source

pub fn map_err<F2, G>(self, g: G) -> Outcome<T, F2>
where G: FnOnce(E) -> F2,

Maps the error value using the provided function.

§Examples
use asupersync::Outcome;

let err: Outcome<i32, &str> = Outcome::err("short");
let mapped = err.map_err(str::len);
assert!(matches!(mapped, Outcome::Err(5)));
Source

pub fn and_then<U, F>(self, f: F) -> Outcome<U, E>
where F: FnOnce(T) -> Outcome<U, E>,

Applies a function to the success value, flattening the result.

This is the monadic bind operation, useful for chaining operations that might fail.

§Examples
use asupersync::Outcome;

fn parse_int(s: &str) -> Outcome<i32, &'static str> {
    s.parse::<i32>().map_err(|_| "parse error").into()
}

fn double(x: i32) -> Outcome<i32, &'static str> {
    Outcome::ok(x * 2)
}

let result = parse_int("21").and_then(double);
assert_eq!(result.unwrap(), 42);

let result = parse_int("abc").and_then(double);
assert!(result.is_err());
Source

pub fn ok_or_else<F2, G>(self, f: G) -> Result<T, F2>
where G: FnOnce() -> F2,

Returns the success value, or computes a fallback from a closure.

Unlike unwrap_or_else, this returns a Result instead of another value of T.

This intentionally collapses every non-Ok outcome (Err, Cancelled, and Panicked) into the same lazily computed fallback error. Use into_result if you need to preserve which terminal outcome occurred.

§Examples
use asupersync::{Outcome, CancelReason};

let ok: Outcome<i32, &str> = Outcome::ok(42);
let result: Result<i32, &str> = ok.ok_or_else(|| "default error");
assert_eq!(result, Ok(42));

let cancelled: Outcome<i32, &str> = Outcome::cancelled(CancelReason::timeout());
let result: Result<i32, &str> = cancelled.ok_or_else(|| "was cancelled");
assert_eq!(result, Err("was cancelled"));
Source

pub fn join(self, other: Outcome<T, E>) -> Outcome<T, E>

Joins this outcome with another, returning the outcome with higher severity.

This implements the lattice join operation for aggregating outcomes from parallel tasks. The outcome with the worst (highest) severity wins.

§Note on Value Handling

When both outcomes are Ok, this method returns self. When both are Cancelled, a strictly stronger CancelReason is retained. Equal- severity cancellation ties remain left-biased and return self.

§Examples
use asupersync::{Outcome, CancelReason};

let ok1: Outcome<i32, &str> = Outcome::ok(1);
let ok2: Outcome<i32, &str> = Outcome::ok(2);
let err: Outcome<i32, &str> = Outcome::err("error");
let cancelled: Outcome<i32, &str> = Outcome::cancelled(CancelReason::timeout());

// Ok + Ok = first Ok (both same severity)
assert!(ok1.clone().join(ok2).is_ok());

// Ok + Err = Err (Err is worse)
assert!(ok1.clone().join(err.clone()).is_err());

// Err + Cancelled = Cancelled (Cancelled is worse)
assert!(err.join(cancelled).is_cancelled());

Implements def.outcome.join_semantics (#31). Left-bias: on equal severity, self (left argument) wins. The only Cancelled + Cancelled special case is when the right-hand cancellation reason has strictly higher severity and therefore strengthens the result. This is intentional: join is associative on severity, but not fully value-commutative. See law.join.assoc (#42).

Source

pub fn unwrap(self) -> T
where E: Debug,

Returns the success value or panics.

§Panics

Panics if the outcome is not Ok.

Source

pub fn expect(self, msg: &str) -> T
where E: Debug,

Unwraps the contained Ok value, panicking with a custom message if not Ok.

Similar to Result::expect, but for Outcome.

§Examples
use asupersync::Outcome;

let outcome: Outcome<u32, &str> = Outcome::ok(42);
assert_eq!(outcome.expect("should be ok"), 42);
§Panics

Panics with the provided message if the outcome is not Ok.

Source

pub fn expect_err(self, msg: &str) -> E
where T: Debug,

Unwraps the contained Err value, panicking with a custom message if not Err.

Similar to Result::expect_err, but for Outcome.

§Examples
use asupersync::Outcome;

let outcome: Outcome<u32, &str> = Outcome::err("failed");
assert_eq!(outcome.expect_err("should be error"), "failed");
§Panics

Panics with the provided message if the outcome is not Err.

Source

pub fn unwrap_or(self, default: T) -> T

Returns the success value or a default.

Source

pub fn unwrap_or_else<F>(self, f: F) -> T
where F: FnOnce() -> T,

Returns the success value or computes it from a closure.

Trait Implementations§

Source§

impl<T, E> Clone for Outcome<T, E>
where T: Clone, E: Clone,

Source§

fn clone(&self) -> Outcome<T, E>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, E> Debug for Outcome<T, E>
where T: Debug, E: Debug,

Source§

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

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

impl<'de, T, E> Deserialize<'de> for Outcome<T, E>
where T: Deserialize<'de>, E: Deserialize<'de>,

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Outcome<T, E>, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T, E> Eq for Outcome<T, E>
where T: Eq, E: Eq,

Source§

impl<T, E> From<Result<T, E>> for Outcome<T, E>

Source§

fn from(result: Result<T, E>) -> Outcome<T, E>

Converts to this type from the input type.
Source§

impl<T, E> FromResidual<Outcome<Infallible, E>> for Outcome<T, E>

Source§

fn from_residual(residual: Outcome<Infallible, E>) -> Outcome<T, E>

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
Source§

impl<T, E> FromResidual<Result<Infallible, E>> for Outcome<T, E>

Source§

fn from_residual(residual: Result<Infallible, E>) -> Outcome<T, E>

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
Source§

impl<T> OutcomeExt<T> for Outcome<T, McpError>

Source§

fn into_mcp_result(self) -> Result<T, McpError>

Convert an Outcome to a McpResult, mapping Cancelled to RequestCancelled error.
Source§

fn map_ok<U>(self, f: impl FnOnce(T) -> U) -> Outcome<U, McpError>

Map the success value, preserving cancellation and panic states.
Source§

impl<T, E> PartialEq for Outcome<T, E>
where T: PartialEq, E: PartialEq,

Source§

fn eq(&self, other: &Outcome<T, E>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, E> Residual<T> for Outcome<Infallible, E>

Source§

type TryType = Outcome<T, E>

🔬This is a nightly-only experimental API. (try_trait_v2_residual)
The “return” type of this meta-function.
Source§

impl<T, E> Serialize for Outcome<T, E>
where T: Serialize, E: Serialize,

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T, E> StructuralPartialEq for Outcome<T, E>
where T: PartialEq, E: PartialEq,

Source§

impl<T, E> Try for Outcome<T, E>

Source§

type Output = T

🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value produced by ? when not short-circuiting.
Source§

type Residual = Outcome<Infallible, E>

🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value passed to FromResidual::from_residual as part of ? when short-circuiting. Read more
Source§

fn from_output(output: <Outcome<T, E> as Try>::Output) -> Outcome<T, E>

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from its Output type. Read more
Source§

fn branch( self, ) -> ControlFlow<<Outcome<T, E> as Try>::Residual, <Outcome<T, E> as Try>::Output>

🔬This is a nightly-only experimental API. (try_trait_v2)
Used in ? to decide whether the operator should produce a value (because this returned ControlFlow::Continue) or propagate a value back to the caller (because this returned ControlFlow::Break). Read more

Auto Trait Implementations§

§

impl<T, E> Freeze for Outcome<T, E>
where T: Freeze, E: Freeze,

§

impl<T, E> RefUnwindSafe for Outcome<T, E>

§

impl<T, E> Send for Outcome<T, E>
where T: Send, E: Send,

§

impl<T, E> Sync for Outcome<T, E>
where T: Sync, E: Sync,

§

impl<T, E> Unpin for Outcome<T, E>
where T: Unpin, E: Unpin,

§

impl<T, E> UnsafeUnpin for Outcome<T, E>
where T: UnsafeUnpin, E: UnsafeUnpin,

§

impl<T, E> UnwindSafe for Outcome<T, E>
where T: UnwindSafe, E: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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