Struct protobuf::MessageField

source ·
pub struct MessageField<T>(pub Option<Box<T>>);
Expand description

Wrapper around Option<Box<T>>, convenient newtype.

§Examples

let mut customer = Customer::new();

// field of type `SingularPtrField` can be initialized like this
customer.address = MessageField::some(make_address());
// or using `Option` and `Into`
customer.address = Some(make_address()).into();

Tuple Fields§

§0: Option<Box<T>>

Implementations§

source§

impl<T> MessageField<T>

source

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

Construct SingularPtrField from given object.

source

pub const fn none() -> MessageField<T>

Construct an empty SingularPtrField.

source

pub fn from_option(option: Option<T>) -> MessageField<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(&self) -> Option<&T>

View data as reference option.

source

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

View data as mutable reference option.

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) -> T
where F: FnOnce() -> T,

Take the data or return supplied default element if empty.

source

pub fn map<U, F>(self, f: F) -> MessageField<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(&self) -> IntoIter<&T>

View data as iterator.

source

pub fn mut_iter(&mut self) -> IntoIter<&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> MessageField<T>

source

pub fn unwrap_or_default(self) -> T

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

source§

impl<M: Message> MessageField<M>

source

pub fn get_or_default(&self) -> &M

Get a reference to contained value or a default instance.

source

pub fn mut_or_insert_default(&mut self) -> &mut M

Get a mutable reference to contained value, initialize if not initialized yet.

Trait Implementations§

source§

impl<T: Clone> Clone for MessageField<T>

source§

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

source§

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

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

impl<T> Default for MessageField<T>

source§

fn default() -> MessageField<T>

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

impl<M: Message> Deref for MessageField<M>

Get a reference to contained value or a default instance if the field is not initialized.

§

type Target = M

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T> From<Option<T>> for MessageField<T>

We don’t have From<Option<Box<T>>> for MessageField<T> because it would make type inference worse.

source§

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

Converts to this type from the input type.
source§

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

source§

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

source§

impl<T> StructuralPartialEq for MessageField<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

impl<T> Unpin for MessageField<T>

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where 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 T
where 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 T
where 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.