pub enum Maybe<T> {
Unspecified,
Specified(T),
}Expand description
The Maybe type represents an optional that might or might not be specified.
An Option is deserialized as None if either the value is not specified or the value is
null. Maybe allows us to distinguish between the two.
§Examples
use s2_common::maybe::Maybe;
#[derive(Debug, PartialEq, Eq, serde::Deserialize)]
pub struct MyStruct {
#[serde(default)]
pub field: Maybe<Option<u32>>,
}
assert_eq!(
MyStruct { field: Maybe::Unspecified },
serde_json::from_str("{}").unwrap(),
);
assert_eq!(
MyStruct { field: Maybe::Specified(None) },
serde_json::from_str(r#"{ "field": null }"#).unwrap(),
);
assert_eq!(
MyStruct { field: Maybe::Specified(Some(10)) },
serde_json::from_str(r#"{ "field": 10 }"#).unwrap(),
);Variants§
Implementations§
Trait Implementations§
Source§impl<'de, T: Deserialize<'de>> Deserialize<'de> for Maybe<T>
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Maybe<T>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl<T: Eq> Eq for Maybe<T>
impl<T> StructuralPartialEq for Maybe<T>
Auto Trait Implementations§
impl<T> Freeze for Maybe<T>where
T: Freeze,
impl<T> RefUnwindSafe for Maybe<T>where
T: RefUnwindSafe,
impl<T> Send for Maybe<T>where
T: Send,
impl<T> Sync for Maybe<T>where
T: Sync,
impl<T> Unpin for Maybe<T>where
T: Unpin,
impl<T> UnwindSafe for Maybe<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