Struct gcollections::wrappers::optional::Optional[][src]

pub struct Optional<T> { /* fields omitted */ }

Methods

impl<T> Optional<T>
[src]

Methods from Deref<Target = Option<T>>

Returns true if the option is a Some value.

Examples

let x: Option<u32> = Some(2);
assert_eq!(x.is_some(), true);

let x: Option<u32> = None;
assert_eq!(x.is_some(), false);

Returns true if the option is a None value.

Examples

let x: Option<u32> = Some(2);
assert_eq!(x.is_none(), false);

let x: Option<u32> = None;
assert_eq!(x.is_none(), true);

Converts from Option<T> to Option<&T>.

Examples

Convert an Option<String> into an Option<usize>, preserving the original. The map method takes the self argument by value, consuming the original, so this technique uses as_ref to first take an Option to a reference to the value inside the original.

let text: Option<String> = Some("Hello, world!".to_string());
// First, cast `Option<String>` to `Option<&String>` with `as_ref`,
// then consume *that* with `map`, leaving `text` on the stack.
let text_length: Option<usize> = text.as_ref().map(|s| s.len());
println!("still can print text: {:?}", text);

Converts from Option<T> to Option<&mut T>.

Examples

let mut x = Some(2);
match x.as_mut() {
    Some(v) => *v = 42,
    None => {},
}
assert_eq!(x, Some(42));

🔬 This is a nightly-only experimental API. (pin)

Converts from Option<T> to Option<PinMut<'_, T>>

Important traits for Iter<'a, A>

Returns an iterator over the possibly contained value.

Examples

let x = Some(4);
assert_eq!(x.iter().next(), Some(&4));

let x: Option<u32> = None;
assert_eq!(x.iter().next(), None);

Important traits for IterMut<'a, A>

Returns a mutable iterator over the possibly contained value.

Examples

let mut x = Some(4);
match x.iter_mut().next() {
    Some(v) => *v = 42,
    None => {},
}
assert_eq!(x, Some(42));

let mut x: Option<u32> = None;
assert_eq!(x.iter_mut().next(), None);

Important traits for &'a mut R

Inserts v into the option if it is None, then returns a mutable reference to the contained value.

Examples

let mut x = None;

{
    let y: &mut u32 = x.get_or_insert(5);
    assert_eq!(y, &5);

    *y = 7;
}

assert_eq!(x, Some(7));

Important traits for &'a mut R

Inserts a value computed from f into the option if it is None, then returns a mutable reference to the contained value.

Examples

let mut x = None;

{
    let y: &mut u32 = x.get_or_insert_with(|| 5);
    assert_eq!(y, &5);

    *y = 7;
}

assert_eq!(x, Some(7));

Takes the value out of the option, leaving a None in its place.

Examples

let mut x = Some(2);
x.take();
assert_eq!(x, None);

let mut x: Option<u32> = None;
x.take();
assert_eq!(x, None);

Trait Implementations

impl<T: Clone> Clone for Optional<T>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T: Copy> Copy for Optional<T>
[src]

impl<T: PartialEq> PartialEq for Optional<T>
[src]

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

This method tests for !=.

impl<T: Eq> Eq for Optional<T>
[src]

impl<T: PartialOrd> PartialOrd for Optional<T>
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<T: Ord> Ord for Optional<T>
[src]

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

impl<T: Debug> Debug for Optional<T>
[src]

Formats the value using the given formatter. Read more

impl<T> Collection for Optional<T>
[src]

impl<T> Deref for Optional<T>
[src]

The resulting type after dereferencing.

Dereferences the value.

impl<T> DerefMut for Optional<T>
[src]

Mutably dereferences the value.

impl<T> Cardinality for Optional<T>
[src]

impl<T> Singleton for Optional<T>
[src]

impl<T> Empty for Optional<T>
[src]

impl<T> Intersection<Optional<T>> for Optional<T> where
    T: Clone + PartialEq
[src]

impl<T> Intersection<T> for Optional<T> where
    T: Clone + PartialEq
[src]

impl Intersection<Optional<i8>> for i8
[src]

impl Intersection<Optional<u8>> for u8
[src]

impl Intersection<Optional<i16>> for i16
[src]

impl Intersection<Optional<u16>> for u16
[src]

impl Intersection<Optional<i32>> for i32
[src]

impl Intersection<Optional<u32>> for u32
[src]

impl Intersection<Optional<i64>> for i64
[src]

impl Intersection<Optional<u64>> for u64
[src]

impl Intersection<Optional<isize>> for isize
[src]

impl Intersection<Optional<usize>> for usize
[src]

impl Intersection<Optional<f32>> for f32
[src]

impl Intersection<Optional<f64>> for f64
[src]

impl Intersection<Optional<bool>> for bool
[src]

impl Intersection<Optional<char>> for char
[src]

impl<T> Difference<Optional<T>> for Optional<T> where
    T: Clone + PartialEq
[src]

impl<T> Difference<T> for Optional<T> where
    T: Clone + PartialEq
[src]

impl Difference<Optional<i8>> for i8
[src]

impl Difference<Optional<u8>> for u8
[src]

impl Difference<Optional<i16>> for i16
[src]

impl Difference<Optional<u16>> for u16
[src]

impl Difference<Optional<i32>> for i32
[src]

impl Difference<Optional<u32>> for u32
[src]

impl Difference<Optional<i64>> for i64
[src]

impl Difference<Optional<u64>> for u64
[src]

impl Difference<Optional<isize>> for isize
[src]

impl Difference<Optional<usize>> for usize
[src]

impl Difference<Optional<f32>> for f32
[src]

impl Difference<Optional<f64>> for f64
[src]

impl Difference<Optional<bool>> for bool
[src]

impl Difference<Optional<char>> for char
[src]

impl<T, U> Disjoint<Optional<U>> for Optional<T> where
    T: Disjoint<U>, 
[src]

impl<T, U> Disjoint<U> for Optional<T> where
    T: Disjoint<U>,
    U: GroundType
[src]

impl<T> Disjoint<Optional<T>> for i8 where
    T: Disjoint<i8>, 
[src]

impl<T> Disjoint<Optional<T>> for u8 where
    T: Disjoint<u8>, 
[src]

impl<T> Disjoint<Optional<T>> for i16 where
    T: Disjoint<i16>, 
[src]

impl<T> Disjoint<Optional<T>> for u16 where
    T: Disjoint<u16>, 
[src]

impl<T> Disjoint<Optional<T>> for i32 where
    T: Disjoint<i32>, 
[src]

impl<T> Disjoint<Optional<T>> for u32 where
    T: Disjoint<u32>, 
[src]

impl<T> Disjoint<Optional<T>> for i64 where
    T: Disjoint<i64>, 
[src]

impl<T> Disjoint<Optional<T>> for u64 where
    T: Disjoint<u64>, 
[src]

impl<T> Disjoint<Optional<T>> for isize where
    T: Disjoint<isize>, 
[src]

impl<T> Disjoint<Optional<T>> for usize where
    T: Disjoint<usize>, 
[src]

impl<T> Disjoint<Optional<T>> for f32 where
    T: Disjoint<f32>, 
[src]

impl<T> Disjoint<Optional<T>> for f64 where
    T: Disjoint<f64>, 
[src]

impl<T> Disjoint<Optional<T>> for bool where
    T: Disjoint<bool>, 
[src]

impl<T> Disjoint<Optional<T>> for char where
    T: Disjoint<char>, 
[src]

impl<T> Contains for Optional<T> where
    T: Eq
[src]

impl<T> Subset<Optional<T>> for Optional<T> where
    T: Subset
[src]

impl<T> ProperSubset<Optional<T>> for Optional<T> where
    T: Subset + PartialEq
[src]

impl<T, U> Overlap<Optional<U>> for Optional<T> where
    T: Overlap<U>, 
[src]

impl<T, U> Overlap<U> for Optional<T> where
    T: Overlap<U>,
    U: GroundType
[src]

impl<T> Overlap<Optional<T>> for i8 where
    T: Overlap<i8>, 
[src]

impl<T> Overlap<Optional<T>> for u8 where
    T: Overlap<u8>, 
[src]

impl<T> Overlap<Optional<T>> for i16 where
    T: Overlap<i16>, 
[src]

impl<T> Overlap<Optional<T>> for u16 where
    T: Overlap<u16>, 
[src]

impl<T> Overlap<Optional<T>> for i32 where
    T: Overlap<i32>, 
[src]

impl<T> Overlap<Optional<T>> for u32 where
    T: Overlap<u32>, 
[src]

impl<T> Overlap<Optional<T>> for i64 where
    T: Overlap<i64>, 
[src]

impl<T> Overlap<Optional<T>> for u64 where
    T: Overlap<u64>, 
[src]

impl<T> Overlap<Optional<T>> for isize where
    T: Overlap<isize>, 
[src]

impl<T> Overlap<Optional<T>> for usize where
    T: Overlap<usize>, 
[src]

impl<T> Overlap<Optional<T>> for f32 where
    T: Overlap<f32>, 
[src]

impl<T> Overlap<Optional<T>> for f64 where
    T: Overlap<f64>, 
[src]

impl<T> Overlap<Optional<T>> for bool where
    T: Overlap<bool>, 
[src]

impl<T> Overlap<Optional<T>> for char where
    T: Overlap<char>, 
[src]

impl<T, U, R> Add<Optional<U>> for Optional<T> where
    T: Add<U, Output = R>, 
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T, U, R> Add<U> for Optional<T> where
    T: Add<U, Output = R>,
    U: GroundType
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T, R> Add<Optional<T>> for i8 where
    T: Add<i8, Output = R>, 
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T, R> Add<Optional<T>> for u8 where
    T: Add<u8, Output = R>, 
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T, R> Add<Optional<T>> for i16 where
    T: Add<i16, Output = R>, 
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T, R> Add<Optional<T>> for u16 where
    T: Add<u16, Output = R>, 
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T, R> Add<Optional<T>> for i32 where
    T: Add<i32, Output = R>, 
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T, R> Add<Optional<T>> for u32 where
    T: Add<u32, Output = R>, 
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T, R> Add<Optional<T>> for i64 where
    T: Add<i64, Output = R>, 
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T, R> Add<Optional<T>> for u64 where
    T: Add<u64, Output = R>, 
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T, R> Add<Optional<T>> for isize where
    T: Add<isize, Output = R>, 
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T, R> Add<Optional<T>> for usize where
    T: Add<usize, Output = R>, 
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T, R> Add<Optional<T>> for f32 where
    T: Add<f32, Output = R>, 
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T, R> Add<Optional<T>> for f64 where
    T: Add<f64, Output = R>, 
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T, R> Add<Optional<T>> for bool where
    T: Add<bool, Output = R>, 
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T, R> Add<Optional<T>> for char where
    T: Add<char, Output = R>, 
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T, U, R> Sub<Optional<U>> for Optional<T> where
    T: Sub<U, Output = R>, 
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl<T, U, R> Sub<U> for Optional<T> where
    T: Sub<U, Output = R>,
    U: GroundType
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl Sub<Optional<i8>> for i8
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl Sub<Optional<u8>> for u8
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl Sub<Optional<i16>> for i16
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl Sub<Optional<u16>> for u16
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl Sub<Optional<i32>> for i32
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl Sub<Optional<u32>> for u32
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl Sub<Optional<i64>> for i64
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl Sub<Optional<u64>> for u64
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl Sub<Optional<isize>> for isize
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl Sub<Optional<usize>> for usize
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl Sub<Optional<f32>> for f32
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl Sub<Optional<f64>> for f64
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl<T, U, R> Mul<Optional<U>> for Optional<T> where
    T: Mul<U, Output = R>, 
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<T, U, R> Mul<U> for Optional<T> where
    T: Mul<U, Output = R>,
    U: GroundType
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<T, R> Mul<Optional<T>> for i8 where
    T: Mul<i8, Output = R>, 
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<T, R> Mul<Optional<T>> for u8 where
    T: Mul<u8, Output = R>, 
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<T, R> Mul<Optional<T>> for i16 where
    T: Mul<i16, Output = R>, 
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<T, R> Mul<Optional<T>> for u16 where
    T: Mul<u16, Output = R>, 
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<T, R> Mul<Optional<T>> for i32 where
    T: Mul<i32, Output = R>, 
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<T, R> Mul<Optional<T>> for u32 where
    T: Mul<u32, Output = R>, 
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<T, R> Mul<Optional<T>> for i64 where
    T: Mul<i64, Output = R>, 
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<T, R> Mul<Optional<T>> for u64 where
    T: Mul<u64, Output = R>, 
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<T, R> Mul<Optional<T>> for isize where
    T: Mul<isize, Output = R>, 
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<T, R> Mul<Optional<T>> for usize where
    T: Mul<usize, Output = R>, 
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<T, R> Mul<Optional<T>> for f32 where
    T: Mul<f32, Output = R>, 
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<T, R> Mul<Optional<T>> for f64 where
    T: Mul<f64, Output = R>, 
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<T, R> Mul<Optional<T>> for bool where
    T: Mul<bool, Output = R>, 
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<T, R> Mul<Optional<T>> for char where
    T: Mul<char, Output = R>, 
[src]

The resulting type after applying the * operator.

Performs the * operation.

Auto Trait Implementations

impl<T> Send for Optional<T> where
    T: Send

impl<T> Sync for Optional<T> where
    T: Sync