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§
Implementations§
Source§impl<L, R> Quither<L, R>
impl<L, R> Quither<L, R>
Sourcepub fn left_or(self, other: L) -> L
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.
Sourcepub fn right_or(self, other: R) -> R
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.
Sourcepub fn both_or(self, l: L, r: R) -> (L, R)
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.
Sourcepub fn left_or_default(self) -> Lwhere
L: Default,
pub fn left_or_default(self) -> Lwhere
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.
Sourcepub fn right_or_default(self) -> Rwhere
R: Default,
pub fn right_or_default(self) -> Rwhere
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.
Sourcepub fn both_or_default(self) -> (L, R)
pub fn both_or_default(self) -> (L, R)
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.
Sourcepub fn left_or_else<F>(self, f: F) -> Lwhere
F: FnOnce() -> L,
pub fn left_or_else<F>(self, f: F) -> Lwhere
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.
Sourcepub fn right_or_else<F>(self, f: F) -> Rwhere
F: FnOnce() -> R,
pub fn right_or_else<F>(self, f: F) -> Rwhere
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.
Sourcepub fn both_or_else<F, G>(self, f: F, g: G) -> (L, R)
pub fn both_or_else<F, G>(self, f: F, g: G) -> (L, 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.
Sourcepub fn left_and_then<F, L2>(self, f: F) -> Quither<L2, R> ⓘ
pub fn left_and_then<F, L2>(self, f: F) -> 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.
Sourcepub fn right_and_then<F, R2>(self, f: F) -> Quither<L, R2> ⓘ
pub fn right_and_then<F, R2>(self, f: F) -> 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>
impl<L, R> Quither<L, R>
Sourcepub fn as_ref(&self) -> Quither<&L, &R> ⓘ
pub fn as_ref(&self) -> Quither<&L, &R> ⓘ
Creates a new variant with references to the contained values.
Sourcepub fn as_mut(&mut self) -> Quither<&mut L, &mut R> ⓘ
pub fn as_mut(&mut self) -> Quither<&mut L, &mut R> ⓘ
Creates a new variant with mutable references to the contained values.
Sourcepub fn as_pin_ref(self: Pin<&Self>) -> Quither<Pin<&L>, Pin<&R>> ⓘ
pub fn as_pin_ref(self: Pin<&Self>) -> Quither<Pin<&L>, Pin<&R>> ⓘ
Creates a new pinned variant with references to the contained values.
Sourcepub fn as_pin_mut(self: Pin<&mut Self>) -> Quither<Pin<&mut L>, Pin<&mut R>> ⓘ
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§impl<L, R> Quither<L, R>
impl<L, R> Quither<L, R>
Sourcepub fn factor_neither(self) -> Option<EitherOrBoth<L, R>>
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>>
impl<L, R> Quither<Option<L>, Option<R>>
Sourcepub fn factor_none(self) -> Option<Quither<L, R>>
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>
impl<L, R> Quither<L, R>
Sourcepub fn insert_left(&mut self, l: L) -> &mut L
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.
Sourcepub fn insert_right(&mut self, r: R) -> &mut R
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.
Sourcepub fn insert_both(&mut self, l: L, r: R) -> (&mut L, &mut R)
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.
Sourcepub fn left_or_insert(&mut self, l: L) -> &mut L
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.
Sourcepub fn right_or_insert(&mut self, r: R) -> &mut R
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.
Sourcepub fn left_or_insert_with<F>(&mut self, f: F) -> &mut Lwhere
F: FnOnce() -> L,
pub fn left_or_insert_with<F>(&mut self, f: F) -> &mut Lwhere
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.
Sourcepub fn right_or_insert_with<F>(&mut self, f: F) -> &mut Rwhere
F: FnOnce() -> R,
pub fn right_or_insert_with<F>(&mut self, f: F) -> &mut Rwhere
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.
Sourcepub fn ensure_left(&mut self, l: L) -> &mut L
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.
Sourcepub fn ensure_right(&mut self, r: R) -> &mut R
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.
Sourcepub fn ensure_left_with<F>(&mut self, f: F) -> &mut Lwhere
F: FnOnce() -> L,
pub fn ensure_left_with<F>(&mut self, f: F) -> &mut Lwhere
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.
Sourcepub fn ensure_right_with<F>(&mut self, f: F) -> &mut Rwhere
F: FnOnce() -> R,
pub fn ensure_right_with<F>(&mut self, f: F) -> &mut Rwhere
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.
Sourcepub fn clear_left(&mut self)
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.
Sourcepub fn clear_right(&mut self)
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>
impl<L, R> Quither<L, R>
Sourcepub fn is_neither(&self) -> bool
pub fn is_neither(&self) -> bool
Returns true if the value is the neither variant.
Sourcepub fn left_and_right(self) -> (Option<L>, Option<R>)
pub fn left_and_right(self) -> (Option<L>, Option<R>)
Returns both values as a tuple of Options.
Sourcepub fn just_right(self) -> Option<R>
pub fn just_right(self) -> Option<R>
Returns the right value if the variant is exactly right.
Sourcepub fn unwrap_left(self) -> Lwhere
R: Debug,
pub fn unwrap_left(self) -> Lwhere
R: Debug,
Unwraps the left value, panicking if not present.
Sourcepub fn unwrap_right(self) -> Rwhere
L: Debug,
pub fn unwrap_right(self) -> Rwhere
L: Debug,
Unwraps the right value, panicking if not present.
Sourcepub fn unwrap_both(self) -> (L, R)
pub fn unwrap_both(self) -> (L, R)
Unwraps both values as a tuple, panicking if not present.
Sourcepub fn expect_left(self, msg: &str) -> Lwhere
R: Debug,
pub fn expect_left(self, msg: &str) -> Lwhere
R: Debug,
Unwraps the left value, panicking with a custom message if not present.
Sourcepub fn expect_right(self, msg: &str) -> Rwhere
L: Debug,
pub fn expect_right(self, msg: &str) -> Rwhere
L: Debug,
Unwraps the right value, panicking with a custom message if not present.
Source§impl<L, R> Quither<L, R>
impl<L, R> Quither<L, R>
Sourcepub fn into_iter_chained(self) -> ChainedIterator<L::IntoIter, R::IntoIter> ⓘ
pub fn into_iter_chained(self) -> ChainedIterator<L::IntoIter, R::IntoIter> ⓘ
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);Sourcepub 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>,
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);Sourcepub 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>,
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);Sourcepub fn into_iter_either(self) -> IterIntoEither<L::IntoIter, R::IntoIter> ⓘwhere
L: IntoIterator,
R: IntoIterator,
pub fn into_iter_either(self) -> IterIntoEither<L::IntoIter, R::IntoIter> ⓘwhere
L: IntoIterator,
R: IntoIterator,
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);Sourcepub fn iter_either(
&self,
) -> IterIntoEither<<&L as IntoIterator>::IntoIter, <&R as IntoIterator>::IntoIter> ⓘ
pub fn iter_either( &self, ) -> IterIntoEither<<&L as IntoIterator>::IntoIter, <&R as IntoIterator>::IntoIter> ⓘ
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);Sourcepub fn iter_either_mut(
&mut self,
) -> IterIntoEither<<&mut L as IntoIterator>::IntoIter, <&mut R as IntoIterator>::IntoIter> ⓘ
pub fn iter_either_mut( &mut self, ) -> IterIntoEither<<&mut L as IntoIterator>::IntoIter, <&mut R as IntoIterator>::IntoIter> ⓘ
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);Sourcepub fn into_iter_either_or_both(
self,
) -> IterIntoEitherOrBoth<L::IntoIter, R::IntoIter> ⓘwhere
L: IntoIterator,
R: IntoIterator,
pub fn into_iter_either_or_both(
self,
) -> IterIntoEitherOrBoth<L::IntoIter, R::IntoIter> ⓘwhere
L: IntoIterator,
R: IntoIterator,
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().
Sourcepub fn iter_either_or_both(
&self,
) -> IterIntoEitherOrBoth<<&L as IntoIterator>::IntoIter, <&R as IntoIterator>::IntoIter> ⓘ
pub fn iter_either_or_both( &self, ) -> IterIntoEitherOrBoth<<&L as IntoIterator>::IntoIter, <&R as IntoIterator>::IntoIter> ⓘ
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().
Sourcepub fn iter_either_or_both_mut(
&mut self,
) -> IterIntoEitherOrBoth<<&mut L as IntoIterator>::IntoIter, <&mut R as IntoIterator>::IntoIter> ⓘ
pub fn iter_either_or_both_mut( &mut self, ) -> IterIntoEitherOrBoth<<&mut L as IntoIterator>::IntoIter, <&mut R as IntoIterator>::IntoIter> ⓘ
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().
Sourcepub fn into_iter_both(self) -> IterIntoBoth<L::IntoIter, R::IntoIter> ⓘwhere
L: IntoIterator,
R: IntoIterator,
pub fn into_iter_both(self) -> IterIntoBoth<L::IntoIter, R::IntoIter> ⓘwhere
L: IntoIterator,
R: IntoIterator,
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);Sourcepub fn iter_both(
&self,
) -> IterIntoBoth<<&L as IntoIterator>::IntoIter, <&R as IntoIterator>::IntoIter> ⓘ
pub fn iter_both( &self, ) -> IterIntoBoth<<&L as IntoIterator>::IntoIter, <&R as IntoIterator>::IntoIter> ⓘ
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);Sourcepub fn iter_both_mut(
&mut self,
) -> IterIntoBoth<<&mut L as IntoIterator>::IntoIter, <&mut R as IntoIterator>::IntoIter> ⓘ
pub fn iter_both_mut( &mut self, ) -> IterIntoBoth<<&mut L as IntoIterator>::IntoIter, <&mut R as IntoIterator>::IntoIter> ⓘ
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>
impl<L, R> Quither<L, R>
Sourcepub fn map2<F, G, L2, R2>(self, f: F, g: G) -> Quither<L2, R2> ⓘ
pub fn map2<F, G, L2, R2>(self, f: F, g: G) -> Quither<L2, 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.
Sourcepub fn map_left<F, L2>(self, f: F) -> Quither<L2, R> ⓘwhere
F: FnOnce(L) -> L2,
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.
Sourcepub fn map_right<F, R2>(self, f: F) -> Quither<L, R2> ⓘwhere
F: FnOnce(R) -> R2,
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.
Sourcepub fn try_map2<F, G, L2, R2, E>(self, f: F, g: G) -> Result<Quither<L2, R2>, E>
pub fn try_map2<F, G, L2, R2, E>(self, f: F, g: G) -> Result<Quither<L2, 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.
Sourcepub fn try_map_left<F, L2, E>(self, f: F) -> Result<Quither<L2, R>, E>
pub fn try_map_left<F, L2, E>(self, f: F) -> Result<Quither<L2, R>, 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.
Sourcepub fn try_map_right<F, R2, E>(self, f: F) -> Result<Quither<L, R2>, E>
pub fn try_map_right<F, R2, E>(self, f: F) -> Result<Quither<L, 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.
Sourcepub fn map_with<Ctx, F, G, L2, R2>(
self,
ctx: Ctx,
f: F,
g: G,
) -> Quither<L2, R2> ⓘ
pub fn map_with<Ctx, F, G, L2, R2>( self, ctx: Ctx, f: F, g: G, ) -> Quither<L2, 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>
impl<T> Quither<T, T>
Sourcepub fn map<F, T2>(self, f: F) -> Quither<T2, T2> ⓘwhere
F: FnMut(T) -> T2,
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.
Sourcepub fn try_map<F, T2, E>(self, f: F) -> Result<Quither<T2, T2>, E>
pub fn try_map<F, T2, E>(self, f: F) -> Result<Quither<T2, 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§
impl<L: Copy, R: Copy> Copy for Quither<L, R>
Source§impl<L, R> Display for Quither<L, R>
Formats the pair type for display, showing the variant and its contents.
impl<L, R> Display for Quither<L, R>
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).
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.
impl<L, R> From<Both<L, R>> for Quither<L, R>
Promotes a type and adds Either and Both variants.
Source§impl<L, R> From<Either<L, R>> for Quither<L, R>
Promotes a type and adds Both and Neither variants.
impl<L, R> From<Either<L, R>> for Quither<L, R>
Promotes a type and adds Both and Neither variants.
Source§impl<L, R> From<EitherOrBoth<L, R>> for Quither<L, R>
Promotes a type without Neither variant to a type with Neither variant.
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
fn from(quither: EitherOrBoth<L, R>) -> Self
Source§impl<L, R> From<EitherOrNeither<L, R>> for Quither<L, R>
Promotes a type without Both variant to a type with Both variant.
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
fn from(quither: EitherOrNeither<L, R>) -> Self
Source§impl<L, R> From<NeitherOrBoth<L, R>> for Quither<L, R>
Promotes a type without Either variant to a type with Either variant.
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
fn from(quither: NeitherOrBoth<L, R>) -> Self
Source§impl<L, R> From<Quither<L, R>> for IterIntoEither<L, R>
impl<L, R> From<Quither<L, R>> for IterIntoEither<L, R>
Source§impl<L, R> From<Quither<L, R>> for IterIntoEitherOrBoth<L, R>
impl<L, R> From<Quither<L, R>> for IterIntoEitherOrBoth<L, R>
Source§impl<L, R> From<Quither<L, R>> for IterIntoBoth<L, R>
impl<L, R> From<Quither<L, R>> for IterIntoBoth<L, R>
Source§impl<L, R> From<Quither<L, R>> for ChainedIterator<L, R>
impl<L, R> From<Quither<L, R>> for ChainedIterator<L, R>
Source§impl<L: Ord, R: Ord> Ord for Quither<L, R>
impl<L: Ord, R: Ord> Ord for Quither<L, R>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<L, R, OL, OR> PartialOrd<Quither<OL, OR>> for Quither<L, R>where
L: PartialOrd<OL>,
R: PartialOrd<OR>,
impl<L, R, OL, OR> PartialOrd<Quither<OL, OR>> for Quither<L, R>where
L: PartialOrd<OL>,
R: PartialOrd<OR>,
Source§impl<L, R> Read for Quither<L, R>
Provides Read, chaining Left then Right for Both, otherwise delegating.
impl<L, R> Read for Quither<L, R>
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>
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)Source§impl<L, R> TryFrom<Quither<L, R>> for NeitherOrBoth<L, R>
Demotes a type with Either variant to a type without Either variant.
impl<L, R> TryFrom<Quither<L, R>> for NeitherOrBoth<L, R>
Demotes a type with Either variant to a type without Either variant.
Source§impl<L, R> TryFrom<Quither<L, R>> for EitherOrBoth<L, R>
Demotes a type with Neither variant to a type without Neither variant.
impl<L, R> TryFrom<Quither<L, R>> for EitherOrBoth<L, R>
Demotes a type with Neither variant to a type without Neither variant.
Source§impl<L, R> TryFrom<Quither<L, R>> for EitherOrNeither<L, R>
Demotes a type with Both variant to a type without Both variant.
impl<L, R> TryFrom<Quither<L, R>> for EitherOrNeither<L, R>
Demotes a type with Both variant to a type without Both variant.
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.
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§impl<L, R> TryFrom<Quither<L, R>> for Neither
Demotes a type with Either and Both variants to a type without those variants.
impl<L, R> TryFrom<Quither<L, R>> for Neither
Demotes a type with Either and Both variants to a type without those variants.
Auto Trait Implementations§
impl<L, R> Freeze for Quither<L, R>
impl<L, R> RefUnwindSafe for Quither<L, R>where
L: RefUnwindSafe,
R: RefUnwindSafe,
impl<L, R> Send for Quither<L, R>
impl<L, R> Sync for Quither<L, R>
impl<L, R> Unpin for Quither<L, R>
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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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