pub enum Maybe<T> {
Absent,
Null,
Value(T),
}Expand description
A serde value that distinguishes between null and missing values.
§Note
When used as a field in a serializable type (although not needed for deserialization), the
attribute #[serde(default, skip_serializing_if = "Maybe::is_absent")] must be placed on the
field.
When used as a field in a deserialization, the attribute #[serde(default)] must be placed on
the field.
§OpenAPI
The override #[schema(nullable, value_type = Option<T>)] must be placed on the field.
Variants§
Absent
The field is absent.
Null
The field is present but is set to null.
Value(T)
The field is present and is set to a value, T.
Implementations§
Source§impl<T> Maybe<T>
impl<T> Maybe<T>
Sourcepub fn map<U>(self, f: impl FnOnce(T) -> U) -> Maybe<U>
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> Maybe<U>
Maps the inner value of Maybe to a new value.
Sourcepub fn into_option_or_if_absent(self, fallback: Option<T>) -> Option<T>
pub fn into_option_or_if_absent(self, fallback: Option<T>) -> Option<T>
Turns this into an Option, but if the value is Absent, the given fallback value is used
instead.
Sourcepub fn into_option_or_if_absent_then(
self,
f: impl FnOnce() -> Option<T>,
) -> Option<T>
pub fn into_option_or_if_absent_then( self, f: impl FnOnce() -> Option<T>, ) -> Option<T>
Turns this into an Option, but if the value is Absent, the given fallback function is
called to produce a fallback value.
Sourcepub fn into_option(self) -> Option<T>
pub fn into_option(self) -> Option<T>
Turns this into an Option.