pub enum Optional<T> {
Set(T),
Unset(T),
}Expand description
A protobuf value from a field that may not be set.
This can be pattern matched with match or if let to determine if the
field is set and access the field data.
Two Optionals are equal if they match both presence and the field values.
Variants§
Set(T)
The field is set; it is present in the serialized message.
- For an
_opt()accessor, this contains aView<impl Proxied>. - For a
_mut()accessor, this contains a [PresentField] that can be used to access the current value, convert toMut, clear presence, or set a new value.
Unset(T)
The field is unset; it is absent in the serialized message.
- For an
_opt()accessor, this contains aView<impl Proxied>with the default value. - For a
_mut()accessor, this contains an [AbsentField] that can be used to access the default or set a new value.
Implementations§
Source§impl<T> Optional<T>
impl<T> Optional<T>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Gets the field value, ignoring whether it was set or not.
Sourcepub fn new(val: T, is_set: bool) -> Self
pub fn new(val: T, is_set: bool) -> Self
Constructs an Optional<T> with a T value and presence bit.
Sourcepub fn into_option(self) -> Option<T>
pub fn into_option(self) -> Option<T>
Converts into an Option of the set value, ignoring any unset value.
Trait Implementations§
impl<T: Copy> Copy for Optional<T>
impl<T: Eq> Eq for Optional<T>
impl<T> StructuralPartialEq for Optional<T>
Auto Trait Implementations§
impl<T> Freeze for Optional<T>where
T: Freeze,
impl<T> RefUnwindSafe for Optional<T>where
T: RefUnwindSafe,
impl<T> Send for Optional<T>where
T: Send,
impl<T> Sync for Optional<T>where
T: Sync,
impl<T> Unpin for Optional<T>where
T: Unpin,
impl<T> UnwindSafe for Optional<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more