Fusion

Struct Fusion 

Source
pub struct Fusion<A, E, T>(/* private fields */);
Expand description

A type that allows chaining multiple validations together while combining their results.

Fusion is particularly useful when you want to accumulate values from multiple successful validations into a single composite value.

Implementations§

Source§

impl<A, E, T> Fusion<A, E, T>

Source

pub fn fuse<A1>(self, other: Valid<A1, E, T>) -> Fusion<A::Out, E, T>
where A: Append<A1>,

Combines this fusion with another validation, using the Append trait to combine their successful values.

§Examples
use tailcall_valid::{Valid, Validator};
let v1: Valid<Vec<i32>, (), ()> = Valid::succeed(vec![1, 2]);
let v2: Valid<Vec<i32>, (), ()> = Valid::succeed(vec![3, 4]);
let fusion = v1.fuse(v2);
let result = fusion.to_result().unwrap();
assert_eq!(result, (vec![1, 2], vec![3, 4]));

Trait Implementations§

Source§

impl<A, E, T> From<Fusion<A, E, T>> for Valid<A, E, T>

Source§

fn from(value: Fusion<A, E, T>) -> Self

Converts a Fusion back into a Valid.

This is typically used at the end of a chain of fuse operations to convert the final result back into a Valid.

§Examples
use tailcall_valid::{Valid, Validator};
let v1: Valid<Vec<i32>, (), ()> = Valid::succeed(vec![1]);
let v2: Valid<Vec<i32>, (), ()> = Valid::succeed(vec![2]);
let fusion = v1.fuse(v2);
let result: Valid<(Vec<i32>, Vec<i32>), (), ()> = Valid::from(fusion);
assert!(result.is_succeed());
Source§

impl<A, E, T> Validator<A, E, T> for Fusion<A, E, T>

Source§

fn to_result(self) -> Result<A, Vec<Cause<E, T>>>

Converts the validation into a Result.
Source§

fn is_succeed(&self) -> bool

Returns true if the validation is successful.
Source§

fn is_fail(&self) -> bool

Returns true if the validation contains errors.
Source§

fn map<A1>(self, f: impl FnOnce(A) -> A1) -> Valid<A1, E, T>

Maps a function over the successful value, transforming it to a new type. Read more
Source§

fn foreach(self, f: impl FnMut(A)) -> Valid<A, E, T>
where A: Clone,

Executes a side effect function if the validation is successful. The original value is preserved. Read more
Source§

fn and<A1>(self, other: Valid<A1, E, T>) -> Valid<A1, E, T>

Combines two validations, keeping the result of the second one if both succeed. If either validation fails, all errors are collected. Read more
Source§

fn zip<A1>(self, other: Valid<A1, E, T>) -> Valid<(A, A1), E, T>

Combines two validations into a tuple of their results. If either validation fails, all errors are collected. Read more
Source§

fn fuse<A1>(self, other: Valid<A1, E, T>) -> Fusion<(A, A1), E, T>

Starts a fusion chain of validations. This allows combining multiple validation results using the Append trait. Read more
Source§

fn trace(self, trace: impl Into<T> + Clone) -> Valid<A, E, T>

Adds trace context to any errors in the validation. Successful validations are unaffected. Read more
Source§

fn fold<A1>( self, ok: impl FnOnce(A) -> Valid<A1, E, T>, err: impl FnOnce() -> Valid<A1, E, T>, ) -> Valid<A1, E, T>

Handles both success and failure cases of a validation. Read more
Source§

fn and_then<B>(self, f: impl FnOnce(A) -> Valid<B, E, T>) -> Valid<B, E, T>

Chains a validation operation by applying a function to a successful value. If the original validation failed, the errors are propagated. Read more
Source§

fn unit(self) -> Valid<(), E, T>

Converts a successful validation to (). Failed validations retain their errors. Read more
Source§

fn some(self) -> Valid<Option<A>, E, T>

Wraps a successful value in Some(_). Read more
Source§

fn map_to<B>(self, b: B) -> Valid<B, E, T>

Maps a successful validation to a constant value. Read more
Source§

fn when(self, f: impl FnOnce() -> bool) -> Valid<(), E, T>

Conditionally validates based on a predicate. If the predicate returns false, succeeds with (). Read more

Auto Trait Implementations§

§

impl<A, E, T> Freeze for Fusion<A, E, T>
where A: Freeze,

§

impl<A, E, T> RefUnwindSafe for Fusion<A, E, T>

§

impl<A, E, T> Send for Fusion<A, E, T>
where A: Send, E: Send, T: Send,

§

impl<A, E, T> Sync for Fusion<A, E, T>
where A: Sync, E: Sync, T: Sync,

§

impl<A, E, T> Unpin for Fusion<A, E, T>
where A: Unpin, E: Unpin, T: Unpin,

§

impl<A, E, T> UnwindSafe for Fusion<A, E, T>
where A: UnwindSafe, E: UnwindSafe, T: 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.
Source§

impl<S, T> ValidInto<T> for S
where T: ValidFrom<S>,

Source§

type Error = <T as ValidFrom<S>>::Error

Source§

type Trace = <T as ValidFrom<S>>::Trace

Source§

fn valid_into( self, ) -> Valid<T, <S as ValidInto<T>>::Error, <S as ValidInto<T>>::Trace>