Skip to main content

Cause

Enum Cause 

Source
pub enum Cause<E> {
    Fail(E),
    Die(String),
    Interrupt(FiberId),
    Both(Box<Cause<E>>, Box<Cause<E>>),
    Then(Box<Cause<E>>, Box<Cause<E>>),
}
Expand description

Effect failure algebra: typed errors, defects, fiber interrupts, and composite causes.

Variants§

§

Fail(E)

Recoverable failure carrying the typed error E.

§

Die(String)

Defect (panic-style) message.

§

Interrupt(FiberId)

Fiber interrupted at fiber_id.

§

Both(Box<Cause<E>>, Box<Cause<E>>)

Parallel composition of two causes.

§

Then(Box<Cause<E>>, Box<Cause<E>>)

Sequential composition: left observed before right.

Implementations§

Source§

impl<E> Cause<E>

Source

pub fn fail(error: E) -> Self

Cause::Fail wrapping error.

Source

pub fn die(message: impl Into<String>) -> Self

Cause::Die with message.

Source

pub fn interrupt(fiber_id: FiberId) -> Self

Cause::Interrupt for fiber_id.

Source

pub fn both(left: Cause<E>, right: Cause<E>) -> Self

Cause::Both combining left and right.

Source

pub fn then(left: Cause<E>, right: Cause<E>) -> Self

Cause::Then sequencing left before right.

Source

pub fn map_fail<E2, F>(self, map: F) -> Cause<E2>
where F: Fn(E) -> E2 + Copy,

Map Cause::Fail payloads with map; preserve other variants.

Source

pub fn fail_option(self) -> Option<E>

Cause::Fail payload as Some, every other variant as None.

Uses crate::foundation::option_::option::from_predicate on the failure value.

Source

pub fn contains<F>(&self, pred: &F) -> bool
where F: Fn(&Cause<E>) -> bool,

Return true if pred matches this cause or any sub-cause (depth-first).

Source

pub fn pretty(&self) -> String
where E: Display + Clone + 'static,

Human-readable tree of this cause (for debugging and logs).

Source§

impl<E> Cause<Cause<E>>

Source

pub fn flatten(self) -> Cause<E>

Flatten a Cause<Cause<E>> into Cause<E>.

Fail(inner) unwraps to inner; structural variants (Both, Then) are recursively flattened; Die and Interrupt are preserved.

Trait Implementations§

Source§

impl<E: Clone> Clone for Cause<E>

Source§

fn clone(&self) -> Cause<E>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<E: Debug> Debug for Cause<E>

Source§

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

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

impl<E: Hash + Eq + PartialEq> Hash for Cause<E>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<E: Hash + Eq + PartialEq> PartialEq for Cause<E>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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<E: Clone + 'static> Semigroup for Cause<E>

Cause<E> with Cause::both forms a commutative semigroup.

Law: combine(combine(a, b), c) ≡ combine(a, combine(b, c)) (Both is associative).

Source§

fn combine(self, other: Self) -> Self

Combine two values associatively.
Source§

fn combine_ref(&self, other: &Self) -> Self
where Self: Clone,

Combine by reference, cloning as needed.
Source§

impl<E: Hash + Eq + PartialEq> Eq for Cause<E>

Auto Trait Implementations§

§

impl<E> Freeze for Cause<E>
where E: Freeze,

§

impl<E> RefUnwindSafe for Cause<E>
where E: RefUnwindSafe,

§

impl<E> Send for Cause<E>
where E: Send,

§

impl<E> Sync for Cause<E>
where E: Sync,

§

impl<E> Unpin for Cause<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for Cause<E>
where E: UnsafeUnpin,

§

impl<E> UnwindSafe for Cause<E>
where 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> EffectHash for T
where T: Hash + ?Sized,

Source§

fn effect_hash(&self) -> u64

Returns a u64 hash of self using the default hasher (Effect.ts-style single-value hash).
Source§

impl<T> Equal for T
where T: PartialEq + ?Sized,

Source§

fn effect_equals(&self, other: &Self) -> bool

Returns whether self and other are structurally equal (defaults to PartialEq::eq).
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> Pipe for T

Source§

fn pipe<F, R>(self, f: F) -> R
where F: FnOnce(Self) -> R,

Applies f to self (F#-style forward pipe).
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<T> EffectData for T
where T: PartialEq + Eq + Hash + ?Sized,