pub enum MayBe<T> {
Is(T),
IsNot,
}
Expand description
Something that may be of the kind of T
.
If a value doesn’t have the kind of T
, this will discard the value and
provide an MayBe::IsNot
. Nevertheless, if the value does have the kind of
T
but cannot be deserialized by T
, this will also fail to deserialize,
making this wrapper “shallow”.
For example, struct
s have the same kind as a JSON object, {}
, If the
contents of said JSON object don’t match what the struct
is expecting,
like if the struct Foo { bar: u32 }
is being matched, as MayBe<Foo>
,
against {"bar": ""}
, then that is an error. However, matching the same
MayBe<Foo>
against a JSON array, []
would not lead to an error, but
to an MayBe::IsNot
.
Can only be used with self-describing formats, like JSON.
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<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T: Ord> Ord for MayBe<T>
impl<T: Ord> Ord for MayBe<T>
Source§impl<T: PartialOrd> PartialOrd for MayBe<T>
impl<T: PartialOrd> PartialOrd for MayBe<T>
impl<T: Copy> Copy for MayBe<T>
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