Enum crokey::OneToThree

source ·
pub enum OneToThree<T> {
    One(T),
    Two(T, T),
    Three(T, T, T),
}
Expand description

An ordered set of 1, 2 or 3 elements, allowing pattern matching.

Implements Copy, Clone, PartialEq, Eq, Debug, etc. if the element type does.

Variants§

§

One(T)

§

Two(T, T)

§

Three(T, T, T)

Implementations§

source§

impl<T> OneToThree<T>

source

pub fn one(a: T) -> OneToThree<T>

source

pub fn two(a: T, b: T) -> OneToThree<T>

source

pub fn three(a: T, b: T, c: T) -> OneToThree<T>

source

pub fn len(&self) -> usize

source

pub fn iter(&self) -> OneToThreeIter<'_, T>

source

pub fn first(&self) -> &T

source

pub fn first_mut(&mut self) -> &mut T

source

pub fn get(&self, i: usize) -> Option<&T>

source

pub fn get_mut(&mut self, i: usize) -> Option<&mut T>

source

pub fn to_vec(self) -> Vec<T>

source

pub fn to_ref_vec(&self) -> Vec<&T>

source

pub fn sorted(self) -> OneToThree<T>
where T: PartialOrd,

source

pub fn map<B, F>(self, f: F) -> OneToThree<B>
where F: Fn(T) -> B,

source

pub fn try_map<B, E, F>(self, f: F) -> Result<OneToThree<B>, E>
where F: Fn(T) -> Result<B, E>,

Trait Implementations§

source§

impl<T> Clone for OneToThree<T>
where T: Clone + Copy,

source§

fn clone(&self) -> OneToThree<T>

Returns a copy 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<T> Debug for OneToThree<T>
where T: Debug,

source§

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

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

impl<T> From<(T, T)> for OneToThree<T>

source§

fn from(t: (T, T)) -> OneToThree<T>

Converts to this type from the input type.
source§

impl<T> From<(T, T, T)> for OneToThree<T>

source§

fn from(t: (T, T, T)) -> OneToThree<T>

Converts to this type from the input type.
source§

impl<T> From<T> for OneToThree<T>

source§

fn from(a: T) -> OneToThree<T>

Converts to this type from the input type.
source§

impl<T> Hash for OneToThree<T>
where T: Hash,

source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

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<'a, T> IntoIterator for &'a OneToThree<T>

§

type Item = &'a T

The type of the elements being iterated over.
§

type IntoIter = OneToThreeIter<'a, T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> OneToThreeIter<'a, T>

Creates an iterator from a value. Read more
source§

impl<T> PartialEq for OneToThree<T>
where T: PartialEq,

source§

fn eq(&self, other: &OneToThree<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> TryFrom<Vec<T>> for OneToThree<T>

§

type Error = &'static str

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

fn try_from( v: Vec<T> ) -> Result<OneToThree<T>, <OneToThree<T> as TryFrom<Vec<T>>>::Error>

Performs the conversion.
source§

impl<T> Copy for OneToThree<T>
where T: Copy,

source§

impl<T> Eq for OneToThree<T>
where T: Eq,

Auto Trait Implementations§

§

impl<T> Freeze for OneToThree<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for OneToThree<T>
where T: RefUnwindSafe,

§

impl<T> Send for OneToThree<T>
where T: Send,

§

impl<T> Sync for OneToThree<T>
where T: Sync,

§

impl<T> Unpin for OneToThree<T>
where T: Unpin,

§

impl<T> UnwindSafe for OneToThree<T>
where T: 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> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
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> ToOwned for T
where T: Clone,

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.