Struct obj_pool::invalid_value::OptionInvalidValue[][src]

pub struct OptionInvalidValue<T: InvalidValue<T> + PartialEq + Copy + Eq + Hash>(_);

Optimization for Option<T> where T implements an InvalidValue trait and reuses on of the possible values of T to represents None. It's basically the same as NonZero*-types but more powerful as it allows to reuse any value, not just 0 for any type, not just integers. As a downside, it's not an Option, it's a separate type which is needed to be handled explicitly.

use obj_pool::invalid_value::{InvalidValue, OptionInvalidValue};

#[derive(PartialEq, Eq, Hash, Copy, Clone)]
struct A(u32);

impl InvalidValue<A> for A {
  fn invalid_value() -> A {
     A(155) // invalid value in our case
  }
}

let mut v: OptionInvalidValue<A> = A(100).into();
assert!(v.is_some());

v = A(155).into();
assert!(v.is_none());

Methods

impl<T: InvalidValue<T> + PartialEq + Copy + Eq + Hash> OptionInvalidValue<T>
[src]

Make a None value

Make an Option<&T>

Get reference to underlying T, panics it it's None.

Get mutable reference to underlying T, panics it it's None.

impl<T: InvalidValue<T> + PartialEq + Copy + Eq + Hash> OptionInvalidValue<T>
[src]

Checks if OptionInvalidValue is Some

Checks if OptionInvalidValue is None

Unwraps the OptionInvalidValue, panics in case of None.

Trait Implementations

impl<T: PartialEq + InvalidValue<T> + PartialEq + Copy + Eq + Hash> PartialEq for OptionInvalidValue<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: Debug + InvalidValue<T> + PartialEq + Copy + Eq + Hash> Debug for OptionInvalidValue<T>
[src]

Formats the value using the given formatter. Read more

impl<T: Copy + InvalidValue<T> + PartialEq + Copy + Eq + Hash> Copy for OptionInvalidValue<T>
[src]

impl<T: Clone + InvalidValue<T> + PartialEq + Copy + Eq + Hash> Clone for OptionInvalidValue<T>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T: Eq + InvalidValue<T> + PartialEq + Copy + Eq + Hash> Eq for OptionInvalidValue<T>
[src]

impl<T: Hash + InvalidValue<T> + PartialEq + Copy + Eq + Hash> Hash for OptionInvalidValue<T>
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl<T: InvalidValue<T> + PartialEq + Copy + Eq + Hash> IntoIterator for OptionInvalidValue<T>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl<T: InvalidValue<T> + PartialEq + Copy + Eq + Hash> From<Option<T>> for OptionInvalidValue<T>
[src]

Performs the conversion.

impl<T: InvalidValue<T> + PartialEq + Copy + Eq + Hash> Into<Option<T>> for OptionInvalidValue<T>
[src]

Performs the conversion.

impl<T: InvalidValue<T> + PartialEq + Copy + Eq + Hash> From<T> for OptionInvalidValue<T>
[src]

Wraps a value in OptionInvalidValue, treats T::invalid_value as None

Performs the conversion.

Auto Trait Implementations

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

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