pub enum Field<T> {
Absent,
Null,
Value(T),
}Expand description
An omitted member, an explicit JSON null, or a modeled value.
Generated structures omit Absent during serialization. Null is always
present on the wire, including for optional document members.
Variants§
Implementations§
Source§impl<T> Field<T>
impl<T> Field<T>
pub fn is_absent(&self) -> bool
pub fn is_null(&self) -> bool
Sourcepub fn is_clear(&self) -> bool
pub fn is_clear(&self) -> bool
Whether this field is explicit null, clearing a clearable input member.
Sourcepub fn map<U>(self, f: impl FnOnce(T) -> U) -> Field<U>
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> Field<U>
Transform a value while preserving omission and explicit null.
Sourcepub fn is_unset(&self) -> bool
pub fn is_unset(&self) -> bool
Absent or null: what a protocol that omits null members leaves out.
pub fn value(&self) -> Option<&T>
pub fn into_value(self) -> Option<T>
pub fn as_deref(&self) -> Option<&T::Target>where
T: Deref,
Trait Implementations§
Source§impl<T, C: Codec<T>> Codec<Field<T>> for Field<C>
impl<T, C: Codec<T>> Codec<Field<T>> for Field<C>
fn serialize<S: Serializer>( value: &Field<T>, serializer: S, ) -> Result<S::Ok, S::Error>
fn deserialize<'de, D: Deserializer<'de>>( deserializer: D, ) -> Result<Field<T>, D::Error>
impl<T: Copy> Copy for Field<T>
Source§impl<'de, T: Deserialize<'de>> Deserialize<'de> for Field<T>
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Field<T>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl<T: Eq> Eq for Field<T>
Source§impl<T: Ord> Ord for Field<T>
impl<T: Ord> Ord for Field<T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl<T: PartialOrd> PartialOrd for Field<T>
impl<T: PartialOrd> PartialOrd for Field<T>
impl<T: PartialEq> StructuralPartialEq for Field<T>
Auto Trait Implementations§
impl<T> Forget for Field<T>
impl<T> Freeze for Field<T>where
T: Freeze,
impl<T> Move for Field<T>
impl<T> RefUnwindSafe for Field<T>where
T: RefUnwindSafe,
impl<T> Send for Field<T>where
T: Send,
impl<T> Sync for Field<T>where
T: Sync,
impl<T> Unpin for Field<T>where
T: Unpin,
impl<T> UnsafeUnpin for Field<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Field<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Output for T
impl<T> Output for T
Source§fn write_json_to(&self, out: &mut dyn Write) -> Result<(), Error>
fn write_json_to(&self, out: &mut dyn Write) -> Result<(), Error>
Stream serialization to a bounded sink. Custom erased outputs can
override this to avoid the default intermediate JSON value.
fn to_json(&self) -> Value
Source§fn write_json(&self, out: &mut Vec<u8>) -> Result<(), Error>
fn write_json(&self, out: &mut Vec<u8>) -> Result<(), Error>
Serializes into
out. Every serializable output writes straight to
bytes; this default, for other implementors, goes through to_json.Source§fn write_json_split(
&self,
members: &[MemberInfo],
out: &mut Vec<u8>,
) -> Result<Vec<(&'static str, String)>, Error>
fn write_json_split( &self, members: &[MemberInfo], out: &mut Vec<u8>, ) -> Result<Vec<(&'static str, String)>, Error>
Serializes into
out without the members members binds to
headers, returning those as (header, text); with a payload member,
out gets that member’s bytes, raw. The default goes through
to_json, as write_json’s does.