Struct protobuf::SingularField

source ·
pub struct SingularField<T> { /* private fields */ }
Expand description

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

Implementations§

source§

impl<T> SingularField<T>

source

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

Construct this object from given value.

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 this object into Option.

source

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

View data as Option.

source

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

View data as mutable Option.

source

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

Unwrap data as reference.

source

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

Unwrap data as mutable reference.

source

pub fn unwrap(self) -> T

Unwrap data, panic if not set.

source

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

Unwrap data or return given default value.

source

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

Unwrap data or return given default value.

source

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

Apply a function to contained element and store result in new SingularPtrField.

source

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

View as iterator over references.

source

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

View as iterator over mutable references.

source

pub fn clear(&mut self)

Clear this object. Note, contained object destructor is not called, so allocated memory could be reused.

source§

impl<T: Default> SingularField<T>

source

pub fn none() -> SingularField<T>

Construct a SingularField with no data.

source

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

Construct SingularField from Option.

source

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

Return data as option, clear this object.

source§

impl<T: Default + Clear> SingularField<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 + Default> Clone for SingularField<T>

source§

fn clone(&self) -> SingularField<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 SingularField<T>

source§

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

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

impl<T: Default> Default for SingularField<T>

source§

fn default() -> SingularField<T>

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

impl<T: Default> From<Option<T>> for SingularField<T>

source§

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

Converts to this type from the input type.
source§

impl<T: Hash> Hash for SingularField<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 SingularField<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<SingularField<T>> for SingularField<T>

source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for SingularField<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.