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>
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.
Source§impl<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.
Source§impl<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§
Source§impl<T: Clone> Clone for MessageField<T>
impl<T: Clone> Clone for MessageField<T>
Source§fn clone(&self) -> MessageField<T>
fn clone(&self) -> MessageField<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T: Debug> Debug for MessageField<T>
impl<T: Debug> Debug for MessageField<T>
Source§impl<T> Default for MessageField<T>
impl<T> Default for MessageField<T>
Source§fn default() -> MessageField<T>
fn default() -> MessageField<T>
Source§impl<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.
Source§impl<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.