pub struct SingularPtrField<T> { /* private fields */ }
Expand description

Like Option<Box<T>>, but keeps the actual element on clear.

Implementations§

source§

impl<T> SingularPtrField<T>

source

pub fn some(value: T) -> SingularPtrField<T>

Construct SingularPtrField from given object.

source

pub fn none() -> SingularPtrField<T>

Construct an empty SingularPtrField.

source

pub fn from_option(option: Option<T>) -> SingularPtrField<T>

Construct SingularPtrField from optional.

source

pub fn is_some(&self) -> bool

True iff this object contains data.

source

pub fn is_none(&self) -> bool

True iff this object contains no data.

source

pub fn into_option(self) -> Option<T>

Convert into Option<T>.

source

pub fn as_ref<'a>(&'a self) -> Option<&'a T>

View data as reference option.

source

pub fn as_mut<'a>(&'a mut self) -> Option<&'a mut T>

View data as mutable reference option.

source

pub fn get_ref<'a>(&'a self) -> &'a T

Get data as reference. Panics if empty.

source

pub fn get_mut_ref<'a>(&'a mut self) -> &'a mut T

Get data as mutable reference. Panics if empty.

source

pub fn unwrap(self) -> T

Take the data. Panics if empty

source

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

Take the data or return supplied default element if empty.

source

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

Take the data or return supplied default element if empty.

source

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

Apply given function to contained data to construct another SingularPtrField. Returns empty SingularPtrField if this object is empty.

source

pub fn iter<'a>(&'a self) -> IntoIter<&'a T>

View data as iterator.

source

pub fn mut_iter<'a>(&'a mut self) -> IntoIter<&'a mut T>

View data as mutable iterator.

source

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

Take data as option, leaving this object empty.

source

pub fn clear(&mut self)

Clear this object, but do not call destructor of underlying data.

source§

impl<T: Default + Clear> SingularPtrField<T>

source

pub fn unwrap_or_default(self) -> T

Get contained data, consume self. Return default value for type if this is empty.

source

pub fn set_default<'a>(&'a mut self) -> &'a mut T

Initialize this object with default value. This operation can be more efficient then construction of clear element, because it may reuse previously contained object.

Trait Implementations§

source§

impl<T: Clone> Clone for SingularPtrField<T>

source§

fn clone(&self) -> SingularPtrField<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> Debug for SingularPtrField<T>

source§

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

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

impl<T> Default for SingularPtrField<T>

source§

fn default() -> SingularPtrField<T>

Returns the “default value” for a type. Read more
source§

impl<T> From<Option<T>> for SingularPtrField<T>

source§

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

Converts to this type from the input type.
source§

impl<T: Hash> Hash for SingularPtrField<T>

source§

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

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 SingularPtrField<T>

§

type Item = &'a T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<&'a T>

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

fn into_iter(self) -> IntoIter<&'a T>

Creates an iterator from a value. Read more
source§

impl<T: PartialEq> PartialEq<SingularPtrField<T>> for SingularPtrField<T>

source§

fn eq(&self, other: &SingularPtrField<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: Eq> Eq for SingularPtrField<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

impl<T> Unpin for SingularPtrField<T>

§

impl<T> UnwindSafe for SingularPtrField<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.