AnyOf

Enum AnyOf 

Source
pub enum AnyOf<L, R = L> {
    Neither,
    Either(EitherOf<L, R>),
    Both(BothOf<L, R>),
}
Expand description

Represents a type that can hold one of several variants: Neither, Either (with Left or Right), or Both (containing both Left and Right values).

This enum allows for representing a flexible combination of values, or the absence of any values.

§Variants

  • Neither: Represents the absence of both Left and Right values.
  • Either: Represents a value that is either Left or Right.
  • Both: Represents a combination of both Left and Right values.

§Type Parameters

  • L: The type of the Left value.
  • R: The type of the Right value. Defaults to the same type as L if not specified.

§Examples

use any_of::{AnyOf, EitherOf, BothOf, LeftOrRight, Map, Right, Left, Neither, Either, Both};

let neither: AnyOf<i32, &str> = Neither;
let neither: AnyOf<i32, &str> = AnyOf::new(None, None);
let left: AnyOf<i32, &str> = Either(Left(42));
let left: AnyOf<i32, &str> = AnyOf::new(Some(42), None);
let both: AnyOf<i32, &str> = Both(BothOf { left: 42, right: "Hello" });
let both: AnyOf<i32, &str> = AnyOf::new(Some(42), Some("Hello"));

assert!(neither.is_neither());
assert!(left.is_left());
assert!(both.is_both());

assert!(neither.map_right(|r| r).is_neither());
assert!(left.map_right(|r| r).is_left());
assert!(left.map_left(|l| l).is_left());
assert!(both.map_left(|l| l).is_both());

Variants§

§

Neither

§

Either(EitherOf<L, R>)

§

Both(BothOf<L, R>)

Implementations§

Source§

impl<LL, LR, RL, RR> AnyOf<AnyOf<LL, LR>, AnyOf<RL, RR>>

Source

pub fn new4( ll: Option<LL>, lr: Option<LR>, rl: Option<RL>, rr: Option<RR>, ) -> Self

Creates a new AnyOf4 instance from four optional values.

The parameters correspond to the ll, lr, rl, and rr positions in the nested AnyOf structure. This mirrors AnyOf::new.

§Examples
use any_of::{AnyOf4, AnyOf};

let value = AnyOf4::new4(Some(1), None::<i32>, None::<i32>, None::<i32>);
assert_eq!(value.ll(), Some(&1));
Source

pub fn from_opt4(opt: Opt4<LL, LR, RL, RR>) -> Self

Builds an AnyOf4 from an Opt4 tuple.

Opt4 is a convenient representation of four optional values.

§Examples
use any_of::{AnyOf4, Opt4};

let tuple: Opt4<i32, i32, i32, i32> = (Some(1), None, None, None);
let value = AnyOf4::from_opt4(tuple);
assert!(value.ll().is_some());
Source

pub fn ll(&self) -> Option<&LL>

Returns the left-left value if it exists.

Source

pub fn lr(&self) -> Option<&LR>

Returns the left-right value if it exists.

Source

pub fn rl(&self) -> Option<&RL>

Returns the right-left value if it exists.

Source

pub fn rr(&self) -> Option<&RR>

Returns the right-right value if it exists.

Source

pub fn opt4(&self) -> Opt4<&LL, &LR, &RL, &RR>

Returns a tuple containing the four optional values represented by this AnyOf4.

This is useful when you need a simple (Option<LL>, Option<LR>, Option<RL>, Option<RR>) representation instead of nested enums.

§Examples
use any_of::{AnyOf4, AnyOf, Opt4};

let any: AnyOf4<i32, i32, i32, i32> = AnyOf4::new_left(AnyOf::new_left(1));
assert_eq!(any.opt4(), (Some(&1), None, None, None));
Source§

impl<LLL, LLR, LRL, LRR, RLL, RLR, RRL, RRR> AnyOf<AnyOf<AnyOf<LLL, LLR>, AnyOf<LRL, LRR>>, AnyOf<AnyOf<RLL, RLR>, AnyOf<RRL, RRR>>>

Source

pub fn new8( lll: Option<LLL>, llr: Option<LLR>, lrl: Option<LRL>, lrr: Option<LRR>, rll: Option<RLL>, rlr: Option<RLR>, rrl: Option<RRL>, rrr: Option<RRR>, ) -> Self

Creates a new AnyOf8 from eight optional values.

§Examples
use any_of::AnyOf8;

let value = AnyOf8::new8(
    Some(1),
    None::<i32>, None::<i32>, None::<i32>,
    None::<i32>, None::<i32>, None::<i32>, None::<i32>,
);
assert!(value.lll().is_some());
Source

pub fn from_opt8(opt: Opt8<LLL, LLR, LRL, LRR, RLL, RLR, RRL, RRR>) -> Self

Builds an AnyOf8 from an Opt8 tuple.

§Examples
use any_of::{AnyOf8, Opt8};

let tuple: Opt8<i32, i32, i32, i32, i32, i32, i32, i32> =
    (Some(1), None, None, None, None, None, None, None);
let value = AnyOf8::from_opt8(tuple);
assert_eq!(value.lll(), Some(&1));
Source

pub fn lll(&self) -> Option<&LLL>

Returns the left-left-left value if it exists.

Source

pub fn llr(&self) -> Option<&LLR>

Returns the left-left-right value if it exists.

Source

pub fn lrl(&self) -> Option<&LRL>

Returns the left-right-left value if it exists.

Source

pub fn lrr(&self) -> Option<&LRR>

Returns the left-right-right value if it exists.

Source

pub fn rll(&self) -> Option<&RLL>

Returns the right-left-left value if it exists.

Source

pub fn rlr(&self) -> Option<&RLR>

Returns the right-left-right value if it exists.

Source

pub fn rrl(&self) -> Option<&RRL>

Returns the right-right-left value if it exists.

Source

pub fn rrr(&self) -> Option<&RRR>

Returns the right-right-right value if it exists.

Source

pub fn opt8(&self) -> Opt8<&LLL, &LLR, &LRL, &LRR, &RLL, &RLR, &RRL, &RRR>

Returns the eight optional values represented by this AnyOf8 as a tuple.

The returned Opt8 allows easier pattern matching and conversion into other structures.

§Examples
use any_of::{AnyOf, AnyOf4, AnyOf8, Opt8};

let any: AnyOf8<i32, i32, i32, i32, i32, i32, i32, i32> =
    AnyOf8::new_left(AnyOf4::new_left(AnyOf::new_left(1)));
let tuple = any.opt8();
assert_eq!(tuple.0, Some(&1));
Source§

impl<LLLL, LLLR, LLRL, LLRR, LRLL, LRLR, LRRL, LRRR, RLLL, RLLR, RLRL, RLRR, RRLL, RRLR, RRRL, RRRR> AnyOf<AnyOf<AnyOf<AnyOf<LLLL, LLLR>, AnyOf<LLRL, LLRR>>, AnyOf<AnyOf<LRLL, LRLR>, AnyOf<LRRL, LRRR>>>, AnyOf<AnyOf<AnyOf<RLLL, RLLR>, AnyOf<RLRL, RLRR>>, AnyOf<AnyOf<RRLL, RRLR>, AnyOf<RRRL, RRRR>>>>

Source

pub fn new16( llll: Option<LLLL>, lllr: Option<LLLR>, llrl: Option<LLRL>, llrr: Option<LLRR>, lrll: Option<LRLL>, lrlr: Option<LRLR>, lrrl: Option<LRRL>, lrrr: Option<LRRR>, rlll: Option<RLLL>, rllr: Option<RLLR>, rlrl: Option<RLRL>, rlrr: Option<RLRR>, rrll: Option<RRLL>, rrlr: Option<RRLR>, rrrl: Option<RRRL>, rrrr: Option<RRRR>, ) -> Self

Creates a new AnyOf16 from sixteen optional values.

§Examples
use any_of::AnyOf16;

let value = AnyOf16::new16(
    Some(1), None::<i32>, None::<i32>, None::<i32>,
    None::<i32>, None::<i32>, None::<i32>, None::<i32>,
    None::<i32>, None::<i32>, None::<i32>, None::<i32>,
    None::<i32>, None::<i32>, None::<i32>, None::<i32>,
);
assert!(value.llll().is_some());
Source

pub fn from_opt16( opt: Opt16<LLLL, LLLR, LLRL, LLRR, LRLL, LRLR, LRRL, LRRR, RLLL, RLLR, RLRL, RLRR, RRLL, RRLR, RRRL, RRRR>, ) -> Self

Builds an AnyOf16 from an Opt16 tuple.

§Examples
use any_of::{AnyOf16, Opt16};

let tuple: Opt16<i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
    i32, i32, i32, i32, i32> =
    (Some(1), None, None, None, None, None, None, None,
     None, None, None, None, None, None, None, None);
let value = AnyOf16::from_opt16(tuple);
assert_eq!(value.llll(), Some(&1));
Source

pub fn llll(&self) -> Option<&LLLL>

Returns the left-left-left-left value if it exists.

Source

pub fn lllr(&self) -> Option<&LLLR>

Returns the left-left-left-right value if it exists.

Source

pub fn llrl(&self) -> Option<&LLRL>

Returns the left-left-right-left value if it exists.

Source

pub fn llrr(&self) -> Option<&LLRR>

Returns the left-left-right-right value if it exists.

Source

pub fn lrll(&self) -> Option<&LRLL>

Returns the left-right-left-left value if it exists.

Source

pub fn lrlr(&self) -> Option<&LRLR>

Returns the left-right-left-right value if it exists.

Source

pub fn lrrl(&self) -> Option<&LRRL>

Returns the left-right-right-left value if it exists.

Source

pub fn lrrr(&self) -> Option<&LRRR>

Returns the left-right-right-right value if it exists.

Source

pub fn rlll(&self) -> Option<&RLLL>

Returns the right-left-left-left value if it exists.

Source

pub fn rllr(&self) -> Option<&RLLR>

Returns the right-left-left-right value if it exists.

Source

pub fn rlrl(&self) -> Option<&RLRL>

Returns the right-left-right-left value if it exists.

Source

pub fn rlrr(&self) -> Option<&RLRR>

Returns the right-left-right-right value if it exists.

Source

pub fn rrll(&self) -> Option<&RRLL>

Returns the right-right-left-left value if it exists.

Source

pub fn rrlr(&self) -> Option<&RRLR>

Returns the right-right-left-right value if it exists.

Source

pub fn rrrl(&self) -> Option<&RRRL>

Returns the right-right-right-left value if it exists.

Source

pub fn rrrr(&self) -> Option<&RRRR>

Returns the right-right-right-right value if it exists.

Source

pub fn opt16( &self, ) -> Opt16<&LLLL, &LLLR, &LLRL, &LLRR, &LRLL, &LRLR, &LRRL, &LRRR, &RLLL, &RLLR, &RLRL, &RLRR, &RRLL, &RRLR, &RRRL, &RRRR>

Returns all sixteen optional values represented by this AnyOf16.

This method provides a direct mapping to the Opt16 type for easier inspection or conversion.

§Examples
use any_of::{AnyOf, AnyOf4, AnyOf8, AnyOf16, Opt16};

let any: AnyOf16<i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32> =
    AnyOf16::new_left(AnyOf8::new_left(AnyOf4::new_left(AnyOf::new_left(1))));
let tuple = any.opt16();
assert_eq!(tuple.0, Some(&1));
Source§

impl<L, R> AnyOf<L, R>

Source

pub fn new(left: Option<L>, right: Option<R>) -> Self

Creates a new AnyOf instance based on the presence of left and right values.

§Parameters
  • left: An Option containing the left value of type L, or None if absent.
  • right: An Option containing the right value of type R, or None if absent.
§Returns
  • Returns Neither if both left and right are None.
  • Returns Either(Left) if left has a value and right is None.
  • Returns Either(Right) if right has a value and left is None.
  • Returns Both if both left and right have values.
§Examples
use any_of::{AnyOf, Either, Both, LeftOrRight};

let neither: AnyOf<i32, &str> = AnyOf::new(None, None);
assert!(neither.is_neither());

let left: AnyOf<i32, &str> = AnyOf::new(Some(42), None);
assert!(left.is_left());

let right: AnyOf<i32, &str> = AnyOf::new(None, Some("Hello"));
assert!(right.is_right());

let both: AnyOf<i32, &str> = AnyOf::new(Some(42), Some("Hello"));
assert!(both.is_both());
Source

pub fn new_neither() -> Self

Creates an Neither variant.

§Examples
use any_of::AnyOf;

let neither: AnyOf<i32, &str> = AnyOf::new_neither();
assert!(neither.is_neither());
Source

pub fn new_left(left: L) -> Self

Creates an Either variant containing a Left value.

§Examples
use any_of::{AnyOf, LeftOrRight};

let left: AnyOf<i32, &str> = AnyOf::new_left(42);
assert!(left.is_left());
Source

pub fn new_right(right: R) -> Self

Creates an Either variant containing a Right value.

§Examples
use any_of::{AnyOf, LeftOrRight};

let right: AnyOf<i32, &str> = AnyOf::new_right("Hello");
assert!(right.is_right());
Source

pub fn new_both(l: L, r: R) -> Self

Creates an Both variant containing both a Left and Right value.

§Examples
use any_of::AnyOf;

let both: AnyOf<i32, &str> = AnyOf::new_both(42, "Hello");
assert!(both.is_both());
Source

pub fn from_both(both: BothOf<L, R>) -> Self

Creates an Both variant from a Both struct.

§Examples
use any_of::{AnyOf, BothOf};

let both_struct = BothOf { left: 42, right: "Hello" };
let both = AnyOf::from_both(both_struct);
assert!(both.is_both());
Source

pub fn from_opt2(any: Opt2<L, R>) -> Self

Creates a new AnyOf instance based on the presence of left and right values.

See Self::new.

Source

pub fn from_either(either: EitherOf<L, R>) -> Self

Creates an AnyOf variant from an Either struct.

§Examples
use any_of::{AnyOf, EitherOf, LeftOrRight};
use any_of::either::EitherOf::{Right, Left};

let either: EitherOf<i32, ()> = Left(42);
let any_of: AnyOf<i32, ()> = AnyOf::from_either(either);
assert!(any_of.is_left());
Source

pub fn into_both(self) -> BothOf<L, R>

Converts the AnyOf variant to a Both struct.

§Panics

This function will panic if self is not a Both variant.

§Examples
use any_of::AnyOf;

let both = AnyOf::new_both(42, "Hello").into_both();
assert_eq!(both.left, 42);
assert_eq!(both.right, "Hello");
Source

pub fn into_either(self) -> EitherOf<L, R>

Converts the AnyOf variant to an Either struct.

§Panics

This function will panic if self is not an Either variant.

§Examples
use any_of::{AnyOf, EitherOf, Left};

let either: EitherOf<i32, ()> = AnyOf::new_left(42).into_either();
assert_eq!(either, Left(42));
Source

pub fn to_either_pair(&self) -> Pair<Option<EitherOf<L, R>>>
where L: Clone, R: Clone,

Converts the current AnyOf variant into a pair of options containing Either variants.

§Returns
  • (Some(Left), None) for Either(Left).
  • (None, Some(Right)) for Either(Right).
  • (Some(Left), Some(Right)) for Both.
  • (None, None) for Neither.
§Examples
use any_of::{AnyOf, Either, Right, Left};

let any_of = AnyOf::new_both(42, "Hello");
let (left, right) = any_of.to_either_pair();
assert_eq!(left, Some(Left(42)));
assert_eq!(right, Some(Right("Hello")));
Source

pub fn has_left(&self) -> bool

True if Left or Both.

Source

pub fn has_right(&self) -> bool

True if Right or Both.

Source

pub fn is_any(&self) -> bool

True if not Neither.

Source

pub fn is_either(&self) -> bool

True if Either.

Source

pub fn is_both(&self) -> bool

True if Both

Source

pub fn is_neither(&self) -> bool

True if Neither

Source

pub fn is_neither_or_both(&self) -> bool

True if not Either

Source

pub fn both_or_none(&self) -> Option<Couple<&L, &R>>

Returns Some((&L, &R)) if self.is_both() is true, or None.

Source

pub fn both_or_else(self, f: impl FnOnce() -> BothOf<L, R>) -> BothOf<L, R>

Returns both values if present, or computes them with the provided function.

Source

pub fn both_or(self, other: BothOf<L, R>) -> BothOf<L, R>

Returns both values if present, or the provided default values.

Source

pub fn unwrap_both(self) -> BothOf<L, R>

Unwraps and returns both values, panicking if not available.

Source

pub fn filter_left(self) -> Self

Filters to keep only the left value if present, otherwise returns Neither.

Source

pub fn filter_right(self) -> Self

Filters to keep only the right value if present, otherwise returns Neither.

Source

pub fn with_right(self, right: R) -> Self

Adds or replaces the right value, keeping or constructing the instance accordingly.

Source

pub fn with_left(self, left: L) -> Self

Adds or replaces the left value, keeping or constructing the instance accordingly.

Source

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

Combines (+ operator) two Either values into a single one.

§General rules
  • Neither is always substituted by the other operand,
  • Both :
    • as left operand : substitutes the other operand,
    • as right operand : completes the other operand,
  • Left or Right :
    • L + R or R + L combines to an instance of Both,
    • L + l or r + R selects the operand placed on the correct side of the operator :
      • leftLeft + rightLeft = leftLeft
      • leftRight + rightRight = rightRight
§All cases
  • Neither cases :
    • Neither + Neither = Neither
    • Neither + other = other
    • self + Neither = self
  • Trivial cases :
    • Left(x) + Left(y) = Left(x)
    • Right(x) + Right(y) = Right(y)
    • Both(x, y) + other = Both(x, y)
  • Combined cases :
    • Left(x) + Right(y) = Both(x, y)
    • Right(x) + Left(y) = Both(y, x)
    • Left(x) + Both(_, y) = Both(x, y)
    • Right(x) + Both(y, _) = Both(y, x)
Source

pub fn filter(self, other: Self) -> Self

Filters (- operator) the current AnyOf instance using another AnyOf instance.

§General rules

The filtering behavior depends on the specific variants of self and other:

  • other == Neither filters nothing (self is returned),
  • other == Both filters all (Neither is returned),
  • Left and Right as other filters the corresponding side of self.
§All cases
  • Neither cases:
    • Neither - other = Neither
    • Left(x) - Left(y) = Neither
    • Right(x) - Right(y) = Neither
    • other - Both(x, y) = Neither
  • Trivial case:
    • other - Neither = other
  • Filtered cases:
    • Left(x) - Right(y) = Left(x)
    • Right(x) - Left(y) = Right(x)
    • Both(x, y) - Right(z) = Left(x)
    • Both(x, y) - Left(z) = Right(y)
§Examples
use any_of::{AnyOf, Both ,BothOf, Either, Left, Neither, Right};

let both = Both(BothOf { left: 5, right: 10 });
let left_only = Either(Left(5));
let right_only = Either(Right(10));
let neither: AnyOf<i32, i32> = Neither;

// Filtering Both with Right results in Left
assert_eq!(both - right_only, left_only);

// Filtering Both with Left results in Right
assert_eq!(both - left_only, right_only);

// Filtering with Neither doesn't affect the original value
assert_eq!(both - neither, both);
assert_eq!(left_only - neither, left_only);
assert_eq!(right_only - neither, right_only);

// Filtering with Both always results in Neither
assert_eq!(both - both, neither);
assert_eq!(left_only - both, neither);
assert_eq!(right_only - both, neither);

Trait Implementations§

Source§

impl<L, R> Add for AnyOf<L, R>

Source§

fn add(self, rhs: Self) -> Self::Output

Source§

type Output = AnyOf<L, R>

The resulting type after applying the + operator.
Source§

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

Source§

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

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<L: Debug, R: Debug> Debug for AnyOf<L, R>

Source§

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

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

impl<L, R> From<(L, R)> for AnyOf<L, R>

Source§

fn from(value: Couple<L, R>) -> Self

Provides indirect conversion of a Couple into an AnyOf, leveraging the From<BothOf<L, R>> for additional flexibility.

Source§

impl<L, R> From<(Option<L>, Option<R>)> for AnyOf<L, R>

Source§

fn from(value: Opt2<L, R>) -> Self

Maps higher-level Opt2 structures into AnyOf using AnyOf::from_opt2.

Source§

impl<L, R> From<AnyOf<L, R>> for Couple<L, R>

Source§

fn from(value: AnyOf<L, R>) -> Self

Turns AnyOf back into Couple, using AnyOf::into_both and [BothOf::into()].

Source§

impl<L: Clone, R: Clone> From<AnyOf<L, R>> for Opt2<L, R>

Source§

fn from(value: AnyOf<L, R>) -> Self

Takes an AnyOf<L, R> and returns an Opt2 pair with cloned optional values.

Source§

impl<L, R> From<AnyOf<L, R>> for BothOf<L, R>

Source§

fn from(value: AnyOf<L, R>) -> Self

Allows conversion of AnyOf back into BothOf using AnyOf::into_both. Useful when strong pair semantics are required.

§Panics

This function will panic if value is not a Both variant.

Source§

impl<L, R> From<AnyOf<L, R>> for EitherOf<L, R>

Source§

fn from(value: AnyOf<L, R>) -> Self

Converts AnyOf back into an EitherOf type using AnyOf::into_either, ensuring proper conversion paths.

§Panics

This function will panic if value is not an Either variant.

Source§

impl<L, R> From<BothOf<L, R>> for AnyOf<L, R>

Source§

fn from(value: BothOf<L, R>) -> Self

Turns a BothOf type into an AnyOf with the help of AnyOf::from_both for consistency.

Source§

impl<L, R> From<EitherOf<L, R>> for AnyOf<L, R>

Source§

fn from(value: EitherOf<L, R>) -> Self

Converts an EitherOf type into an AnyOf type by internally delegating to AnyOf::from_either.

Source§

impl<L: Hash, R: Hash> Hash for AnyOf<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, R> LeftOrRight<L, R> for AnyOf<L, R>

Source§

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

Returns Some(&L) if self.has_left() is true, or None.

Source§

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

Returns Some(&R) if self.has_right() is true, or None.

Source§

fn is_left(&self) -> bool

Checks if the LeftOrRight<L, R> value is the L variant. Read more
Source§

fn is_right(&self) -> bool

Checks if the LeftOrRight<L, R> value is the R variant. Read more
Source§

fn opt2(&self) -> Opt2<&L, &R>

Returns references to the L or R values as a tuple of Option. Read more
Source§

impl<L, R> Map<L, R> for AnyOf<L, R>

Source§

type Output<L2, R2> = AnyOf<L2, R2>

Source§

fn map<FL, FR, L2, R2>(self, fl: FL, fr: FR) -> Self::Output<L2, R2>
where FL: FnOnce(L) -> L2, FR: FnOnce(R) -> R2,

Transforms the L or R value using separate functions, depending on the variant. Read more
Source§

fn map_left<FL, L2>(self, f: FL) -> Self::Output<L2, R>
where Self: Sized, FL: FnOnce(L) -> L2,

Transforms the L value using a provided function. Read more
Source§

fn map_right<FR, R2>(self, f: FR) -> Self::Output<L, R2>
where Self: Sized, FR: FnOnce(R) -> R2,

Transforms the R value using a provided function. Read more
Source§

impl<L, R> Not for AnyOf<L, R>

Source§

fn not(self) -> Self::Output

Swaps (! operator) the left and right components, creating a new AnyOf with reversed types.

§Returns

A new AnyOf<R, L> instance where the left and right components have been swapped.

  • If self is Neither, the result will also be Neither.
  • If self is a Left, the result will contain the value as a Right.
  • If self is a Right, the result will contain the value as a Left.
  • If self is a Both, the left and right values are swapped in the result.
Source§

type Output = AnyOf<R, L>

The resulting type after applying the ! operator.
Source§

impl<L: PartialEq, R: PartialEq> PartialEq for AnyOf<L, R>

Source§

fn eq(&self, other: &AnyOf<L, R>) -> 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<L, R, FL, FR, L2, R2> Shr<BothOf<FL, FR>> for AnyOf<L, R>
where FL: FnOnce(L) -> L2, FR: FnOnce(R) -> R2,

Source§

fn shr(self, rhs: BothOf<FL, FR>) -> Self::Output

Maps two functions with the parts of this AnyOf

§Examples
use any_of::{AnyOf, Left, Unwrap};

let left_fn = |x: i32| x * 2;
let right_fn  = |y: i32| y + 3;
let both_fn = (left_fn, right_fn).into();

let both:AnyOf<i32, i32> = (5, 10).into();
let result = both >> both_fn;
assert_eq!(result, (10, 13).into());

let left = AnyOf::Either(Left(25));
let left_result = left >> both_fn;
assert_eq!(left_result.unwrap_left(), 50);
Source§

type Output = <AnyOf<L, R> as Map<L, R>>::Output<L2, R2>

The resulting type after applying the >> operator.
Source§

impl<L, R> Sub for AnyOf<L, R>

Source§

fn sub(self, rhs: Self) -> Self::Output

Source§

type Output = AnyOf<L, R>

The resulting type after applying the - operator.
Source§

impl<L, R> Swap<L, R> for AnyOf<L, R>

Source§

type Output = <AnyOf<L, R> as Not>::Output

Source§

fn swap(self) -> <Self as Swap<L, R>>::Output
where Self: Sized,

Swaps the left and right values of this dyn LeftOrRight instance. Read more
Source§

impl<L, R> Unwrap<L, R> for AnyOf<L, R>

Source§

fn left_or_else(self, f: impl FnOnce() -> L) -> L

Returns the left value if present, or computes it with the provided function.

Source§

fn right_or_else(self, f: impl FnOnce() -> R) -> R

Returns the right value if present, or computes it with the provided function.

Source§

fn left_or(self, l: L) -> L
where Self: Sized,

Returns the left value or a provided default. Read more
Source§

fn right_or(self, r: R) -> R
where Self: Sized,

Returns the right value or a provided default. Read more
Source§

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

Returns the left value or a default value. Read more
Source§

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

Returns the right value or a default value. Read more
Source§

fn expect_left(self, msg: &str) -> L
where Self: Sized,

Extracts the left value, panicking with the provided message if the variant is Right. Read more
Source§

fn expect_right(self, msg: &str) -> R
where Self: Sized,

Extracts the right value, panicking with the provided message if the variant is Left. Read more
Source§

fn unwrap_left(self) -> L
where Self: Sized,

Extracts the left value, panicking if the variant is Right. Read more
Source§

fn unwrap_right(self) -> R
where Self: Sized,

Extracts the right value, panicking if the variant is Left. Read more
Source§

impl<L: Copy, R: Copy> Copy for AnyOf<L, R>

Source§

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

Source§

impl<L, R> StructuralPartialEq for AnyOf<L, R>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<L, R> UnwindSafe for AnyOf<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, 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.