pub enum Optional<T> {
Present(T),
NotPresent,
Null,
}
Expand description
Represents a value that can either exist, not exist, or be null
This is a helper object for building Attributes. When including it in an
attribute use #[serde(skip_serializing_if = "Optional::is_not_present", default)]
.
Variants§
Present(T)
The key was present in the document and had a value
NotPresent
The key was not present
Null
The key was present and was null
Implementations§
Source§impl<T> Optional<T>
impl<T> Optional<T>
Sourcepub fn is_present(&self) -> bool
pub fn is_present(&self) -> bool
The key was present and had a value
Sourcepub fn is_not_present(&self) -> bool
pub fn is_not_present(&self) -> bool
The key was not present
Sourcepub fn map<U, F>(self, f: F) -> Optional<U>where
F: FnOnce(T) -> U,
pub fn map<U, F>(self, f: F) -> Optional<U>where
F: FnOnce(T) -> U,
Map the value if it was present
Sourcepub fn map_null<F>(self, f: F) -> Option<T>where
F: FnOnce() -> T,
pub fn map_null<F>(self, f: F) -> Option<T>where
F: FnOnce() -> T,
Maps Present
to Some
, calls f
is Null
and maps the result to Some
,
maps NotPresent
to None
Sourcepub fn as_mut(&mut self) -> Optional<&mut T>
pub fn as_mut(&mut self) -> Optional<&mut T>
Converts from &mut Optional<T>
to Optional<&mut T>
Sourcepub fn expect(self, msg: &str) -> T
pub fn expect(self, msg: &str) -> T
Unwraps an Optional, yeilding the content of a Present
§Panics
Panics if the value is not a Present
with a custom panic message provided by msg
Sourcepub fn unwrap(self) -> T
pub fn unwrap(self) -> T
Move the value v
out of the Optional<T>
if it is Present(v)
.
§Panics
Panics if the value is not a Present
Sourcepub fn unwrap_or_null(self, null: T) -> T
pub fn unwrap_or_null(self, null: T) -> T
Sourcepub fn unwrap_or_else_null<F>(self, null: F) -> Twhere
F: FnOnce() -> T,
pub fn unwrap_or_else_null<F>(self, null: F) -> Twhere
F: FnOnce() -> T,
Unwraps if Present
, calls null
and returns the result if Null
§Panics
Panics if the value is NotPresent