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>
impl<A, E, T> Fusion<A, E, T>
Sourcepub fn fuse<A1>(self, other: Valid<A1, E, T>) -> Fusion<A::Out, E, T>where
A: Append<A1>,
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>
impl<A, E, T> From<Fusion<A, E, T>> for Valid<A, E, T>
Source§fn from(value: Fusion<A, E, T>) -> Self
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>
impl<A, E, T> Validator<A, E, T> for Fusion<A, E, T>
Source§fn is_succeed(&self) -> bool
fn is_succeed(&self) -> bool
Returns true if the validation is successful.
Source§fn map<A1>(self, f: impl FnOnce(A) -> A1) -> Valid<A1, E, T>
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,
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>
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>
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>
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 moreSource§fn trace(self, trace: impl Into<T> + Clone) -> Valid<A, E, T>
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>
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>
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>
fn unit(self) -> Valid<(), E, T>
Converts a successful validation to
().
Failed validations retain their errors. Read moreAuto 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>
impl<A, E, T> Sync for Fusion<A, E, T>
impl<A, E, T> Unpin for Fusion<A, E, T>
impl<A, E, T> UnwindSafe for Fusion<A, E, T>
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