among

Trait IntoAmong

source
pub trait IntoAmong: Sized {
    // Provided methods
    fn into_among(self, into_left: Option<bool>) -> Among<Self, Self, Self>  { ... }
    fn into_among_with<F>(self, into_left: F) -> Among<Self, Self, Self> 
       where F: FnOnce(&Self) -> Option<bool> { ... }
}
Expand description

Provides methods for converting a type Self into among a Left Middle or Right variant of Among<Self, Self>.

The into_among method takes a bool to determine whether to convert to Left or Right.

The into_among_with method takes a predicate function to determine whether to convert to Left Middle or Right.

Provided Methods§

source

fn into_among(self, into_left: Option<bool>) -> Among<Self, Self, Self>

Converts self into a Left variant of Among<Self, Self> if into_left is Some(true).

Converts self into a Middle variant of Among<Self, Self> if into_left is None.

Converts self into a Right variant of Among<Self, Self> if into_left is Some(false).

§Examples
use among::{IntoAmong, Left, Right, Middle};

let x = 0;
assert_eq!(x.into_among(Some(true)), Left(x));
assert_eq!(x.into_among(Some(false)), Right(x));
assert_eq!(x.into_among(None), Middle(x));
source

fn into_among_with<F>(self, into_left: F) -> Among<Self, Self, Self>
where F: FnOnce(&Self) -> Option<bool>,

Converts self into a Left variant of Among<Self, Self> if into_left(&self) returns Some(true).

Converts self into a Middle variant of Among<Self, Self> if into_left(&self) returns None.

Converts self into a Right variant of Among<Self, Self> if into_left(&self) returns Some(false).

§Examples
use among::{IntoAmong, Left, Right, Middle};

fn is(x: &u8) -> Option<bool> {
    if x % 3 == 0 {
        None
    } else if x % 3 == 1 {
        Some(true)
    } else {
        Some(false)
    }
}

let x = 0;
assert_eq!(x.into_among_with(is), Middle(x));

let x = 1;
assert_eq!(x.into_among_with(is), Left(x));

let x = 2;
assert_eq!(x.into_among_with(is), Right(x));

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T> IntoAmong for T