Skip to main content

Quither

Enum Quither 

Source
pub enum Quither<L, R> {
    Neither,
    Left(L),
    Right(R),
    Both(L, R),
}
Expand description

An enum that represents either an empty value, left value, right value, or both values.

Variants§

§

Neither

§

Left(L)

§

Right(R)

§

Both(L, R)

Implementations§

Source§

impl<L, R> Quither<L, R>

Source

pub fn left_or(self, other: L) -> L

Returns the left value, or the provided value if not present.

If the left value is present, returns it. Otherwise, returns the provided value.

Source

pub fn right_or(self, other: R) -> R

Returns the right value, or the provided value if not present.

If the right value is present, returns it. Otherwise, returns the provided value.

Source

pub fn both_or(self, l: L, r: R) -> (L, R)

Returns both values as a tuple, or the provided values if either side is missing.

If both values are present, returns them as a tuple. If either side is missing, returns the provided value for that side.

Source

pub fn left_or_default(self) -> L
where L: Default,

Returns the left value, or the default value if not present.

If the left value is present, returns it. Otherwise, returns the default value for the type.

Source

pub fn right_or_default(self) -> R
where R: Default,

Returns the right value, or the default value if not present.

If the right value is present, returns it. Otherwise, returns the default value for the type.

Source

pub fn both_or_default(self) -> (L, R)
where L: Default, R: Default,

Returns both values as a tuple, or default values if either side is missing.

If both values are present, returns them as a tuple. If either side is missing, returns the default value for that side.

Source

pub fn left_or_else<F>(self, f: F) -> L
where F: FnOnce() -> L,

Returns the left value, or computes it from a closure if not present.

If the left value is present, returns it. Otherwise, returns the result of the closure.

Source

pub fn right_or_else<F>(self, f: F) -> R
where F: FnOnce() -> R,

Returns the right value, or computes it from a closure if not present.

If the right value is present, returns it. Otherwise, returns the result of the closure.

Source

pub fn both_or_else<F, G>(self, f: F, g: G) -> (L, R)
where F: FnOnce() -> L, G: FnOnce() -> R,

Returns both values as a tuple, or computes missing values from closures.

If both values are present, returns them as a tuple. If either side is missing, computes the missing value using the provided closure.

Source

pub fn left_and_then<F, L2>(self, f: F) -> Quither<L2, R>
where F: FnOnce(L) -> Quither<L2, R>,

Applies a function to the left value if present, rewrapping the result.

If the left value is present, applies the function and returns the result. Otherwise, returns the original value with the same variant.

Source

pub fn right_and_then<F, R2>(self, f: F) -> Quither<L, R2>
where F: FnOnce(R) -> Quither<L, R2>,

Applies a function to the right value if present, rewrapping the result.

If the right value is present, applies the function and returns the result. Otherwise, returns the original value with the same variant.

Source§

impl<L, R> Quither<L, R>

Source

pub fn as_ref(&self) -> Quither<&L, &R>

Creates a new variant with references to the contained values.

Source

pub fn as_mut(&mut self) -> Quither<&mut L, &mut R>

Creates a new variant with mutable references to the contained values.

Source

pub fn as_pin_ref(self: Pin<&Self>) -> Quither<Pin<&L>, Pin<&R>>

Creates a new pinned variant with references to the contained values.

Source

pub fn as_pin_mut(self: Pin<&mut Self>) -> Quither<Pin<&mut L>, Pin<&mut R>>

Creates a new pinned variant with mutable references to the contained values.

Source

pub fn as_deref(&self) -> Quither<&L::Target, &R::Target>
where L: Deref, R: Deref,

Returns a new value using the Deref trait for L and R values.

Source

pub fn as_deref_mut(&mut self) -> Quither<&mut L::Target, &mut R::Target>
where L: DerefMut, R: DerefMut,

Returns a new value using the DerefMut trait for L and R values.

Source§

impl<L, R> Quither<L, R>

Source

pub fn factor_neither(self) -> Option<EitherOrBoth<L, R>>

Factor out the Neither variant out from the type, converting the type into Option<NewType>>, where NewType is the type of the type excluding the Neither variant.

Only available for types that include the Neither variant and at least one of Either or Both. Converts the value into an Option of a type that does not include the Neither variant. Returns None if the value is Neither; otherwise, returns Some with the corresponding variant.

Source§

impl<L, R> Quither<Option<L>, Option<R>>

Source

pub fn factor_none(self) -> Option<Quither<L, R>>

Factors out None values from a pair of Options, returning None if both are None.

For types of pairs of Option, this method returns an Option of a pair type without Option. If both values are None, returns None. If only one is Some, returns the corresponding variant. If both are Some, returns Both. The output type may differ from the input type depending on the variants present. See also the note about Both types returning EitherOrBoth.

Source§

impl<L, R> Quither<L, R>

Source

pub fn insert_left(&mut self, l: L) -> &mut L

Inserts a left value if not present and returns a mutable reference to it.

If the left value is already present, returns it. If the current variant is Right, promotes to Both and inserts the left value. If the current variant is Neither, promotes to Left. If the current variant is Both, returns the left value. Only available for types supporting the necessary variant transitions.

Source

pub fn insert_right(&mut self, r: R) -> &mut R

Inserts a right value if not present and returns a mutable reference to it.

If the right value is already present, returns it. If the current variant is Left, promotes to Both and inserts the right value. If the current variant is Neither, promotes to Right. If the current variant is Both, returns the right value. Only available for types supporting the necessary variant transitions.

Source

pub fn insert_both(&mut self, l: L, r: R) -> (&mut L, &mut R)

Inserts both left and right values, returning mutable references to both.

If the current variant is not Both, promotes to Both and inserts the values. Only available for types that can represent the Both variant.

Source

pub fn left_or_insert(&mut self, l: L) -> &mut L

Returns a mutable reference to the left value, inserting one if not present.

If the left value is already present, returns it. Otherwise, inserts the provided value (using promotion if necessary) and returns a mutable reference to it. Only available for types supporting the necessary variant transitions.

Source

pub fn right_or_insert(&mut self, r: R) -> &mut R

Returns a mutable reference to the right value, inserting one if not present.

If the right value is already present, returns it. Otherwise, inserts the provided value (using promotion if necessary) and returns a mutable reference to it. Only available for types supporting the necessary variant transitions.

Source

pub fn left_or_insert_with<F>(&mut self, f: F) -> &mut L
where F: FnOnce() -> L,

Returns a mutable reference to the left value, inserting one with a closure if not present.

If the left value is already present, returns it. Otherwise, inserts a value produced by the closure (using promotion if necessary) and returns a mutable reference to it. Only available for types supporting the necessary variant transitions.

Source

pub fn right_or_insert_with<F>(&mut self, f: F) -> &mut R
where F: FnOnce() -> R,

Returns a mutable reference to the right value, inserting one with a closure if not present.

If the right value is already present, returns it. Otherwise, inserts a value produced by the closure (using promotion if necessary) and returns a mutable reference to it. Only available for types supporting the necessary variant transitions.

Source

pub fn ensure_left(&mut self, l: L) -> &mut L

Ensures the left value is present, keeping the right value if possible.

If the left value is already present, returns it. If not, inserts a value (using the provided value or closure) and returns a mutable reference to it. If possible, keeps the right value (promoting to Both if supported), otherwise may discard it. Only available for types that can represent the left value.

Source

pub fn ensure_right(&mut self, r: R) -> &mut R

Ensures the right value is present, keeping the left value if possible.

If the right value is already present, returns it. If not, inserts a value (using the provided closure) and returns a mutable reference to it. If possible, keeps the left value (promoting to Both if supported), otherwise may discard it. Only available for types that can represent the right value.

Source

pub fn ensure_left_with<F>(&mut self, f: F) -> &mut L
where F: FnOnce() -> L,

Ensure the left value is present. If possible, keep the right value too.

If the left value is already present, do nothing and return the left value. If the left value is not present, then:

  • If it can “promote” the variant (Right => Both, Neither => Left), then do so.
  • Otherwise, set the variant to Left (dispose the right value even if it is present). And set the left value to the given closure’s return value and return it.
Source

pub fn ensure_right_with<F>(&mut self, f: F) -> &mut R
where F: FnOnce() -> R,

Ensures the right value is present, keeping the left value if possible.

If the right value is already present, returns it. If not, inserts a value (using the provided closure) and returns a mutable reference to it. If possible, keeps the left value (promoting to Both if supported), otherwise may discard it. Only available for types that can represent the right value.

Source

pub fn clear_left(&mut self)

Clears the left value.

If the current variant is Left, then set the variant to Neither. If the current variant is Both, then set the variant to Right and keep the right value. Otherwise, do nothing.

Source

pub fn clear_right(&mut self)

Clears the right value.

If the current variant is Right, then set the variant to Neither. If the current variant is Both, then set the variant to Left and keep the left value. Otherwise, do nothing.

Source§

impl<L, R> Quither<L, R>

Source

pub fn has_left(&self) -> bool

Returns true if the value contains a left value.

Source

pub fn has_right(&self) -> bool

Returns true if the value contains a right value.

Source

pub fn is_left(&self) -> bool

Returns true if the value is the left variant.

Source

pub fn is_right(&self) -> bool

Returns true if the value is the right variant.

Source

pub fn is_neither(&self) -> bool

Returns true if the value is the neither variant.

Source

pub fn is_both(&self) -> bool

Returns true if the value is the both variant.

Source

pub fn left(self) -> Option<L>

Returns Some if the left value is present, or None otherwise.

Source

pub fn right(self) -> Option<R>

Returns Some if the right value is present, or None otherwise.

Source

pub fn left_and_right(self) -> (Option<L>, Option<R>)

Returns both values as a tuple of Options.

Source

pub fn just_left(self) -> Option<L>

Returns the left value if the variant is exactly left.

Source

pub fn just_right(self) -> Option<R>

Returns the right value if the variant is exactly right.

Source

pub fn both(self) -> Option<(L, R)>

Returns both values as a tuple if the variant is both.

Source

pub fn flip(self) -> Quither<R, L>

Returns a new value with left and right swapped.

Source

pub fn unwrap_left(self) -> L
where R: Debug,

Unwraps the left value, panicking if not present.

Source

pub fn unwrap_right(self) -> R
where L: Debug,

Unwraps the right value, panicking if not present.

Source

pub fn unwrap_both(self) -> (L, R)
where L: Debug, R: Debug,

Unwraps both values as a tuple, panicking if not present.

Source

pub fn expect_left(self, msg: &str) -> L
where R: Debug,

Unwraps the left value, panicking with a custom message if not present.

Source

pub fn expect_right(self, msg: &str) -> R
where L: Debug,

Unwraps the right value, panicking with a custom message if not present.

Source

pub fn expect_both(self, msg: &str) -> (L, R)
where L: Debug, R: Debug,

Unwraps both values as a tuple, panicking with a custom message if not present.

Source§

impl<L, R> Quither<L, R>

Source

pub fn into_iter_chained(self) -> ChainedIterator<L::IntoIter, R::IntoIter>
where L: IntoIterator, R: IntoIterator<Item = L::Item>,

Iterates all items from the left iterator, then all items from the right iterator.

The returned iterator’s Item type is the common item type of both iterators. Left and right iterator item types must be the same. Yields all items from the left, then all from the right (like chain).

§Sample
use quither::Quither;

let q = Quither::Both(vec![1, 2, 3], vec![4, 5]);
let mut iter = q.into_iter_chained();

assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), Some(3));
assert_eq!(iter.next(), Some(4));
assert_eq!(iter.next(), Some(5));
assert_eq!(iter.next(), None);
Source

pub fn iter_chained( &self, ) -> ChainedIterator<<&L as IntoIterator>::IntoIter, <&R as IntoIterator>::IntoIter>
where for<'a> &'a L: IntoIterator, for<'a> &'a R: IntoIterator<Item = <&'a L as IntoIterator>::Item>,

Iterates all items from the left iterator, then all items from the right iterator by reference.

The returned iterator’s Item type is the common item type of both reference iterators. Left and right iterator item types must be the same. Yields all items from the left, then all from the right (like chain).

§Sample
use quither::Quither;

let q = Quither::Both(vec![1, 2, 3], vec![4, 5]);
let mut iter = q.iter_chained();

assert_eq!(iter.next(), Some(&1));
assert_eq!(iter.next(), Some(&2));
assert_eq!(iter.next(), Some(&3));
assert_eq!(iter.next(), Some(&4));
assert_eq!(iter.next(), Some(&5));
assert_eq!(iter.next(), None);
Source

pub fn iter_chained_mut( &mut self, ) -> ChainedIterator<<&mut L as IntoIterator>::IntoIter, <&mut R as IntoIterator>::IntoIter>
where for<'a> &'a mut L: IntoIterator, for<'a> &'a mut R: IntoIterator<Item = <&'a mut L as IntoIterator>::Item>,

Iterates all items from the left iterator, then all items from the right iterator by mutable reference.

The returned iterator’s Item type is the common item type of both mutable reference iterators. Left and right iterator item types must be the same. Yields all items from the left, then all from the right (like chain).

§Sample
use quither::Quither;

let mut q = Quither::Both(vec![1, 2, 3], vec![4, 5]);
let mut iter = q.iter_chained_mut();

assert_eq!(iter.next(), Some(&mut 1));
assert_eq!(iter.next(), Some(&mut 2));
assert_eq!(iter.next(), Some(&mut 3));
assert_eq!(iter.next(), Some(&mut 4));
assert_eq!(iter.next(), Some(&mut 5));
assert_eq!(iter.next(), None);
Source

pub fn into_iter_either(self) -> IterIntoEither<L::IntoIter, R::IntoIter>

Iterates items from both iterators, wrapping each in Either::Left or Either::Right.

The returned iterator’s Item type is Either<L::Item, R::Item>. Yields all items from the left iterator as Left, then all items from the right iterator as Right (in order, like chain).

§Sample
use quither::{Either, Quither};

let q = Quither::Both(vec![1, 2, 3], vec!['a', 'b']);
let mut iter = q.into_iter_either();

assert_eq!(iter.next(), Some(Either::Left(1)));
assert_eq!(iter.next(), Some(Either::Left(2)));
assert_eq!(iter.next(), Some(Either::Left(3)));
assert_eq!(iter.next(), Some(Either::Right('a')));
assert_eq!(iter.next(), Some(Either::Right('b')));
assert_eq!(iter.next(), None);
Source

pub fn iter_either( &self, ) -> IterIntoEither<<&L as IntoIterator>::IntoIter, <&R as IntoIterator>::IntoIter>
where for<'a> &'a L: IntoIterator, for<'a> &'a R: IntoIterator,

Iterates items from both iterators by reference, wrapping each in Either::Left or Either::Right.

The returned iterator’s Item type is Either<L::Item, R::Item>. Yields all items from the left iterator as Left, then all items from the right iterator as Right (in order, like chain).

§Sample
use quither::{Either, Quither};

let q = Quither::Both(vec![1, 2, 3], vec!['a', 'b']);
let mut iter = q.iter_either();

assert_eq!(iter.next(), Some(Either::Left(&1)));
assert_eq!(iter.next(), Some(Either::Left(&2)));
assert_eq!(iter.next(), Some(Either::Left(&3)));
assert_eq!(iter.next(), Some(Either::Right(&'a')));
assert_eq!(iter.next(), Some(Either::Right(&'b')));
assert_eq!(iter.next(), None);
Source

pub fn iter_either_mut( &mut self, ) -> IterIntoEither<<&mut L as IntoIterator>::IntoIter, <&mut R as IntoIterator>::IntoIter>
where for<'a> &'a mut L: IntoIterator, for<'a> &'a mut R: IntoIterator,

Iterates items from both iterators by mutable reference, wrapping each in Either::Left or Either::Right.

The returned iterator’s Item type is Either<L::Item, R::Item>. Yields all items from the left iterator as Left, then all items from the right iterator as Right (in order, like chain).

§Sample
use quither::{Either, Quither};

let mut q = Quither::Both(vec![1, 2, 3], vec!['a', 'b']);
let mut iter = q.iter_either_mut();

assert_eq!(iter.next(), Some(Either::Left(&mut 1)));
assert_eq!(iter.next(), Some(Either::Left(&mut 2)));
assert_eq!(iter.next(), Some(Either::Left(&mut 3)));
assert_eq!(iter.next(), Some(Either::Right(&mut 'a')));
assert_eq!(iter.next(), Some(Either::Right(&mut 'b')));
assert_eq!(iter.next(), None);
Source

pub fn into_iter_either_or_both( self, ) -> IterIntoEitherOrBoth<L::IntoIter, R::IntoIter>

Iterates items from both iterators in parallel, yielding EitherOrBoth::Both(l, r) if both have items, or Left(l)/Right(r) if only one side has items left.

The returned iterator’s Item type is EitherOrBoth<L::Item, R::Item>.

§Sample
use quither::{EitherOrBoth, Quither};

let q = Quither::Both(vec![1, 2, 3], vec!['a', 'b']);
let mut iter = q.into_iter_either_or_both();

assert_eq!(iter.next(), Some(EitherOrBoth::Both(1, 'a')));
assert_eq!(iter.next(), Some(EitherOrBoth::Both(2, 'b')));
assert_eq!(iter.next(), Some(EitherOrBoth::Left(3)));
assert_eq!(iter.next(), None);

Note: If the value is not ::Both, this method behaves similarly to into_iter_either().

Source

pub fn iter_either_or_both( &self, ) -> IterIntoEitherOrBoth<<&L as IntoIterator>::IntoIter, <&R as IntoIterator>::IntoIter>
where for<'a> &'a L: IntoIterator, for<'a> &'a R: IntoIterator,

Iterates items from both iterators in parallel by reference, yielding EitherOrBoth::Both(l, r) if both have items, or Left(l)/Right(r) if only one side has items left.

The returned iterator’s Item type is EitherOrBoth<L::Item, R::Item>.

§Sample
use quither::{EitherOrBoth, Quither};

let q = Quither::Both(vec![1, 2, 3], vec!['a', 'b']);
let mut iter = q.iter_either_or_both();

assert_eq!(iter.next(), Some(EitherOrBoth::Both(&1, &'a')));
assert_eq!(iter.next(), Some(EitherOrBoth::Both(&2, &'b')));
assert_eq!(iter.next(), Some(EitherOrBoth::Left(&3)));
assert_eq!(iter.next(), None);

Note: If the value is not ::Both, this method behaves similarly to iter_either().

Source

pub fn iter_either_or_both_mut( &mut self, ) -> IterIntoEitherOrBoth<<&mut L as IntoIterator>::IntoIter, <&mut R as IntoIterator>::IntoIter>
where for<'a> &'a mut L: IntoIterator, for<'a> &'a mut R: IntoIterator,

Iterates items from both iterators in parallel by mutable reference, yielding EitherOrBoth::Both(l, r) if both have items, or Left(l)/Right(r) if only one side has items left.

The returned iterator’s Item type is EitherOrBoth<L::Item, R::Item>.

§Sample
use quither::{EitherOrBoth, Quither};

let mut q = Quither::Both(vec![1, 2, 3], vec!['a', 'b']);
let mut iter = q.iter_either_or_both_mut();

assert_eq!(iter.next(), Some(EitherOrBoth::Both(&mut 1, &mut 'a')));
assert_eq!(iter.next(), Some(EitherOrBoth::Both(&mut 2, &mut 'b')));
assert_eq!(iter.next(), Some(EitherOrBoth::Left(&mut 3)));
assert_eq!(iter.next(), None);

Note: If the value is not ::Both, this method behaves similarly to iter_either_mut().

Source

pub fn into_iter_both(self) -> IterIntoBoth<L::IntoIter, R::IntoIter>

Iterates pairs of items from both iterators as long as both have items (like zip).

The returned iterator’s Item type is Both<L::Item, R::Item>.

§Sample
use quither::{Both, Quither};

let q = Quither::Both(vec![1, 2, 3], vec!['a', 'b']);
let mut iter = q.into_iter_both();

assert_eq!(iter.next(), Some(Both::Both(1, 'a')));
assert_eq!(iter.next(), Some(Both::Both(2, 'b')));
assert_eq!(iter.next(), None);
Source

pub fn iter_both( &self, ) -> IterIntoBoth<<&L as IntoIterator>::IntoIter, <&R as IntoIterator>::IntoIter>
where for<'a> &'a L: IntoIterator, for<'a> &'a R: IntoIterator,

Iterates pairs of items from both iterators by reference as long as both have items (like zip).

The returned iterator’s Item type is Both<L::Item, R::Item>.

§Sample
use quither::{Both, Quither};

let q = Quither::Both(vec![1, 2, 3], vec!['a', 'b']);
let mut iter = q.iter_both();

assert_eq!(iter.next(), Some(Both::Both(&1, &'a')));
assert_eq!(iter.next(), Some(Both::Both(&2, &'b')));
assert_eq!(iter.next(), None);
Source

pub fn iter_both_mut( &mut self, ) -> IterIntoBoth<<&mut L as IntoIterator>::IntoIter, <&mut R as IntoIterator>::IntoIter>
where for<'a> &'a mut L: IntoIterator, for<'a> &'a mut R: IntoIterator,

Iterates pairs of items from both iterators by mutable reference as long as both have items (like zip).

The returned iterator’s Item type is Both<L::Item, R::Item>.

§Sample
use quither::{Both, Quither};

let mut q = Quither::Both(vec![1, 2, 3], vec!['a', 'b']);
let mut iter = q.iter_both_mut();

assert_eq!(iter.next(), Some(Both::Both(&mut 1, &mut 'a')));
assert_eq!(iter.next(), Some(Both::Both(&mut 2, &mut 'b')));
assert_eq!(iter.next(), None);
Source§

impl<L, R> Quither<L, R>

Source

pub fn map2<F, G, L2, R2>(self, f: F, g: G) -> Quither<L2, R2>
where F: FnOnce(L) -> L2, G: FnOnce(R) -> R2,

Applies separate functions to each variant, transforming both sides.

For types with Either or Both variants, applies f to the left value and g to the right value, returning a new pair type with the results. If Both is present, both functions are applied. If Neither is present, returns Neither.

Source

pub fn map_left<F, L2>(self, f: F) -> Quither<L2, R>
where F: FnOnce(L) -> L2,

Applies a function to the left value, leaving the right unchanged.

For types with Either or Both variants, applies f to the left value. The right value is unchanged. If Both is present, only the left value is transformed. If Neither is present, returns Neither.

Source

pub fn map_right<F, R2>(self, f: F) -> Quither<L, R2>
where F: FnOnce(R) -> R2,

Applies a function to the right value, leaving the left unchanged.

For types with Either or Both variants, applies f to the right value. The left value is unchanged. If Both is present, only the right value is transformed. If Neither is present, returns Neither.

Source

pub fn try_map2<F, G, L2, R2, E>(self, f: F, g: G) -> Result<Quither<L2, R2>, E>
where F: FnOnce(L) -> Result<L2, E>, G: FnOnce(R) -> Result<R2, E>,

Applies separate functions to each variant, returning a new pair type with the results.

Applies f to the left value and g to the right value, and factor out the error. The functors are applied in strictly f then g order, and if either functor returns an error, the following functors are not applied and the error is returned.

Source

pub fn try_map_left<F, L2, E>(self, f: F) -> Result<Quither<L2, R>, E>
where F: FnOnce(L) -> Result<L2, E>,

Applies a function to the left value, returning a new pair type with the results.

Applies f to the left value, and factor out the error. The right value is unchanged. If Both is present, only the left value is transformed. If Neither is present, returns Neither.

Source

pub fn try_map_right<F, R2, E>(self, f: F) -> Result<Quither<L, R2>, E>
where F: FnOnce(R) -> Result<R2, E>,

Applies a function to the right value, returning a new pair type with the results.

Applies f to the right value, and factor out the error. The left value is unchanged. If Both is present, only the right value is transformed. If Neither is present, returns Neither.

Source

pub fn map_with<Ctx, F, G, L2, R2>( self, ctx: Ctx, f: F, g: G, ) -> Quither<L2, R2>
where Ctx: Clone, F: FnOnce(Ctx, L) -> L2, G: FnOnce(Ctx, R) -> R2,

Applies functions to each variant with a shared, clonable context, for types with Both.

For types with Either and Both, applies f to the left value and g to the right value, both with a cloned context. If Both is present, both functions are applied with cloned contexts. If Neither is present, returns Neither.

Source§

impl<T> Quither<T, T>

Source

pub fn map<F, T2>(self, f: F) -> Quither<T2, T2>
where F: FnMut(T) -> T2,

Applies a function to both values, for types with identical left and right types, with Both.

For types with Both variant, applies f to the left value and the right value, in this order.

Source

pub fn try_map<F, T2, E>(self, f: F) -> Result<Quither<T2, T2>, E>
where F: FnMut(T) -> Result<T2, E>,

Applies a function to both values, for types with identical left and right types, with Both.

Applies f to both left and right existing values in this order, and if any of the functor calls return an error, then the error is returned.

Trait Implementations§

Source§

impl<L: Clone, R: Clone> Clone for Quither<L, R>

Source§

fn clone(&self) -> Quither<L, R>

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<L: Copy, R: Copy> Copy for Quither<L, R>

Source§

impl<L: Debug, R: Debug> Debug for Quither<L, R>

Source§

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

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

impl<L, R> Display for Quither<L, R>
where L: Display, R: Display,

Formats the pair type for display, showing the variant and its contents.

Requires both L: Display and R: Display. The output format reflects the variant and its inner value(s).

Source§

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

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

impl<L: Eq, R: Eq> Eq for Quither<L, R>

Source§

impl<L, R> From<Both<L, R>> for Quither<L, R>

Promotes a type and adds Either and Both variants.

Source§

fn from(both: Both<L, R>) -> Self

Converts to this type from the input type.
Source§

impl<L, R> From<Either<L, R>> for Quither<L, R>

Promotes a type and adds Both and Neither variants.

Source§

fn from(either: Either<L, R>) -> Self

Converts to this type from the input type.
Source§

impl<L, R> From<EitherOrBoth<L, R>> for Quither<L, R>

Promotes a type without Neither variant to a type with Neither variant.

Source§

fn from(quither: EitherOrBoth<L, R>) -> Self

Converts to this type from the input type.
Source§

impl<L, R> From<EitherOrNeither<L, R>> for Quither<L, R>

Promotes a type without Both variant to a type with Both variant.

Source§

fn from(quither: EitherOrNeither<L, R>) -> Self

Converts to this type from the input type.
Source§

impl<L, R> From<Neither> for Quither<L, R>

Promotes a type and adds Either and Both variants.

Source§

fn from(_neither: Neither) -> Self

Converts to this type from the input type.
Source§

impl<L, R> From<NeitherOrBoth<L, R>> for Quither<L, R>

Promotes a type without Either variant to a type with Either variant.

Source§

fn from(quither: NeitherOrBoth<L, R>) -> Self

Converts to this type from the input type.
Source§

impl<L, R> From<Quither<L, R>> for IterIntoEither<L, R>
where L: Iterator, R: Iterator,

Source§

fn from(q: Quither<L, R>) -> Self

Converts to this type from the input type.
Source§

impl<L, R> From<Quither<L, R>> for IterIntoEitherOrBoth<L, R>
where L: Iterator, R: Iterator,

Source§

fn from(q: Quither<L, R>) -> Self

Converts to this type from the input type.
Source§

impl<L, R> From<Quither<L, R>> for IterIntoBoth<L, R>
where L: Iterator, R: Iterator,

Source§

fn from(q: Quither<L, R>) -> Self

Converts to this type from the input type.
Source§

impl<L, R> From<Quither<L, R>> for ChainedIterator<L, R>
where L: Iterator, R: Iterator<Item = L::Item>,

Source§

fn from(q: Quither<L, R>) -> Self

Converts to this type from the input type.
Source§

impl<L: Hash, R: Hash> Hash for Quither<L, R>

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<L: Ord, R: Ord> Ord for Quither<L, R>

Source§

fn cmp(&self, other: &Quither<L, R>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<L, R, OL, OR> PartialEq<Quither<OL, OR>> for Quither<L, R>
where L: PartialEq<OL>, R: PartialEq<OR>,

Source§

fn eq(&self, other: &Quither<OL, OR>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<L, R, OL, OR> PartialOrd<Quither<OL, OR>> for Quither<L, R>
where L: PartialOrd<OL>, R: PartialOrd<OR>,

Source§

fn partial_cmp(&self, other: &Quither<OL, OR>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<L, R> Read for Quither<L, R>
where L: Read, R: Read,

Provides Read, chaining Left then Right for Both, otherwise delegating.

Requires both L: Read and R: Read. For the Left, Right, or Neither variants, this simply delegates to the inner value or returns Ok(0). For the Both variant, it first tries to read from Left; if that returns 0, it then reads from Right. This behavior differs from std::io::Read::chain, which never retries the first reader after it returns 0 bytes.

Source§

fn read(&mut self, buf: &mut [u8]) -> IoResult<usize>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · Source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
Source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · Source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Reads all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · Source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Reads all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · Source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Reads the exact number of bytes required to fill buf. Read more
Source§

fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
Source§

fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Reads the exact number of bytes required to fill cursor. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Read. Read more
1.0.0 · Source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · Source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
Source§

fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>
where Self: Sized,

🔬This is a nightly-only experimental API. (read_array)
Read and return a fixed array of bytes from this source. Read more
Source§

fn read_le<T>(&mut self) -> Result<T, Error>
where T: FromEndianBytes, Self: Sized,

🔬This is a nightly-only experimental API. (read_le)
Read and return a type (e.g. an integer) in little-endian order. Read more
Source§

fn read_be<T>(&mut self) -> Result<T, Error>
where T: FromEndianBytes, Self: Sized,

🔬This is a nightly-only experimental API. (read_le)
Read and return a type (e.g. an integer) in big-endian order. Read more
Source§

impl<L, R> TryFrom<Quither<L, R>> for NeitherOrBoth<L, R>

Demotes a type with Either variant to a type without Either variant.

Source§

type Error = Either<L, R>

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

fn try_from(quither: Quither<L, R>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<L, R> TryFrom<Quither<L, R>> for EitherOrBoth<L, R>

Demotes a type with Neither variant to a type without Neither variant.

Source§

type Error = Neither

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

fn try_from(quither: Quither<L, R>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<L, R> TryFrom<Quither<L, R>> for EitherOrNeither<L, R>

Demotes a type with Both variant to a type without Both variant.

Source§

type Error = Both<L, R>

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

fn try_from(quither: Quither<L, R>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<L, R> TryFrom<Quither<L, R>> for Both<L, R>

Demotes a type with Either and Neither variants to a type without those variants.

Source§

type Error = EitherOrNeither<L, R>

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

fn try_from(quither: Quither<L, R>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<L, R> TryFrom<Quither<L, R>> for Neither

Demotes a type with Either and Both variants to a type without those variants.

Source§

type Error = EitherOrBoth<L, R>

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

fn try_from(quither: Quither<L, R>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<L, R> TryFrom<Quither<L, R>> for Either<L, R>

Demotes a type with Either and Neither variants to a type without those variants.

Source§

type Error = NeitherOrBoth<L, R>

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

fn try_from(quither: Quither<L, R>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<L, R> Freeze for Quither<L, R>
where L: Freeze, R: Freeze,

§

impl<L, R> RefUnwindSafe for Quither<L, R>

§

impl<L, R> Send for Quither<L, R>
where L: Send, R: Send,

§

impl<L, R> Sync for Quither<L, R>
where L: Sync, R: Sync,

§

impl<L, R> Unpin for Quither<L, R>
where L: Unpin, R: Unpin,

§

impl<L, R> UnsafeUnpin for Quither<L, R>
where L: UnsafeUnpin, R: UnsafeUnpin,

§

impl<L, R> UnwindSafe for Quither<L, R>
where L: UnwindSafe, R: 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> 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> 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.