Struct protobuf::MessageField
source · [−]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
sourceimpl<T> MessageField<T>
impl<T> MessageField<T>
sourcepub fn some(value: T) -> MessageField<T>
pub fn some(value: T) -> MessageField<T>
Construct SingularPtrField
from given object.
sourcepub const fn none() -> MessageField<T>
pub const fn none() -> MessageField<T>
Construct an empty SingularPtrField
.
sourcepub fn from_option(option: Option<T>) -> MessageField<T>
pub fn from_option(option: Option<T>) -> MessageField<T>
Construct SingularPtrField
from optional.
sourcepub fn into_option(self) -> Option<T>
pub fn into_option(self) -> Option<T>
Convert into Option<T>
.
sourcepub fn unwrap_or_else<F>(self, f: F) -> Twhere
F: FnOnce() -> T,
pub fn unwrap_or_else<F>(self, f: F) -> Twhere
F: FnOnce() -> T,
Take the data or return supplied default element if empty.
sourcepub fn map<U, F>(self, f: F) -> MessageField<U>where
F: FnOnce(T) -> U,
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.
sourceimpl<T: Default> MessageField<T>
impl<T: Default> MessageField<T>
sourcepub fn unwrap_or_default(self) -> T
pub fn unwrap_or_default(self) -> T
Get contained data, consume self. Return default value for type if this is empty.
sourceimpl<M: Message> MessageField<M>
impl<M: Message> MessageField<M>
sourcepub fn get_or_default(&self) -> &M
pub fn get_or_default(&self) -> &M
Get a reference to contained value or a default instance.
sourcepub fn mut_or_insert_default(&mut self) -> &mut M
pub fn mut_or_insert_default(&mut self) -> &mut M
Get a mutable reference to contained value, initialize if not initialized yet.
Trait Implementations
sourceimpl<T: Clone> Clone for MessageField<T>
impl<T: Clone> Clone for MessageField<T>
sourcefn clone(&self) -> MessageField<T>
fn clone(&self) -> MessageField<T>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl<T: Debug> Debug for MessageField<T>
impl<T: Debug> Debug for MessageField<T>
sourceimpl<T> Default for MessageField<T>
impl<T> Default for MessageField<T>
sourcefn default() -> MessageField<T>
fn default() -> MessageField<T>
sourceimpl<M: Message> Deref for MessageField<M>
impl<M: Message> Deref for MessageField<M>
Get a reference to contained value or a default instance if the field is not initialized.
sourceimpl<T> From<Option<T>> for MessageField<T>
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.