Struct optional::Optioned [] [src]

pub struct Optioned<T: Noned + Sized + Copy> {
    // some fields omitted
}

An Option-like structure that takes only as much space as the enclosed value, at the cost of removing one particular None value from the value domain (see Noned)

Methods

impl<T: Noned + Sized + Copy> Optioned<T>
[src]

fn some(t: T) -> Self

Create an Optioned<T> that is some(t).

# Panics

panics if the supplied value is the None value

# Examples

 Optioned::<i32>::some(1); // Optioned(1)
 Optioned::<f64>::some(std::f64::NAN); // panic!s

fn none() -> Self

Create an Optioned<T> that is none().

# Examples

 Optioned::<u16>::none(); // Optioned(std::u16::MAX)

fn is_none(&self) -> bool

Returns true if this Optioned is None, false otherwise.

fn is_some(&self) -> bool

Returns true if this Optioned contains a value, false otherwise.

fn expect(&self, msg: &str) -> T

Unwraps the value, if any, else panics with the given message.

# Panics

if self is None

# Examples

For Some(_), the corresponding value is returned.

 assert_eq!(42u8, Optioned::some(42u8).expect("FAIL"));

On None, it panics with the given message.

Optioned::<u8>::none().expect("FAIL"); // panics with FAIL

fn unwrap(&self) -> T

Unwraps the value, if any, else panics with "unwrap called on None".

# Panics

if self is None

# Examples

For Some(_), the corresponding value is returned.

 assert_eq!(42u8, Optioned::some(42u8).unwrap());

On None, it panics with the given message.

Optioned::<u8>::none().unwrap(); // panics

fn unwrap_or(&self, def: T) -> T

fn unwrap_or_else<F>(self, f: F) -> T where F: FnOnce() -> T

fn map<U, F>(self, f: F) -> Option<U> where F: FnOnce(T) -> U

fn map_t<U, F>(self, f: F) -> Self where F: FnOnce(T) -> T

fn map_or<U, F>(self, default: U, f: F) -> U where F: FnOnce(T) -> U

fn map_or_else<U, D, F>(self, default: D, f: F) -> U where D: FnOnce() -> U, F: FnOnce(T) -> U

fn take(&mut self) -> Option<T>

fn as_slice<'a>(&'a self) -> &'a [T]

Return a possibly empty slice over the contained value, if any.

# Examples ```

use optional::Optioned;

assert_eq!(&[42], Optioned::some(42u8).as_slice()); assert!(Optioned::::none().as_slice().is_empty()); ```

fn iter(&self) -> OptionedIter<T>

Trait Implementations

impl<T: Clone + Noned + Sized + Copy> Clone for Optioned<T>
[src]

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

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)
1.0.0

Performs copy-assignment from source. Read more

impl<T: Copy + Noned + Sized + Copy> Copy for Optioned<T>
[src]

impl<T> PartialEq for Optioned<T> where T: PartialEq + Noned + Sized + Copy
[src]

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<T> Eq for Optioned<T> where T: PartialEq + Noned + Sized + Copy + Eq
[src]

impl<T: Noned + Sized + Copy + Debug> Debug for Optioned<T>
[src]

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

Formats the value using the given formatter.

impl<'a, T: Noned + Sized + Copy> From<&'a Option<T>> for Optioned<T>
[src]

fn from(o: &Option<T>) -> Optioned<T>

Performs the conversion.

impl<T: Noned + Sized + Copy> From<Option<T>> for Optioned<T>
[src]

fn from(o: Option<T>) -> Optioned<T>

Performs the conversion.

impl<T: Noned + Sized + Copy> Into<Option<T>> for Optioned<T>
[src]

fn into(self) -> Option<T>

Performs the conversion.