pub struct NullableTilde<T>(pub Option<T>);Expand description
Serialize None as YAML tilde (~) while otherwise behaving like Option<T>.
Some(value) is serialized transparently as value. None is serialized
as ~ instead of the serializer’s regular null spelling. Deserialization
delegates to Option<T>, so ~, null, and empty YAML values all become
NullableTilde(None).
use serde::Serialize;
use serde_saphyr::NullableTilde;
#[derive(Serialize)]
struct Config {
maybe: NullableTilde<String>,
}
let cfg = Config { maybe: NullableTilde(None) };
let yaml = serde_saphyr::to_string(&cfg).unwrap();
assert_eq!(yaml, "maybe: ~\n");Tuple Fields§
§0: Option<T>Trait Implementations§
Source§impl<T: Clone> Clone for NullableTilde<T>
impl<T: Clone> Clone for NullableTilde<T>
Source§fn clone(&self) -> NullableTilde<T>
fn clone(&self) -> NullableTilde<T>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for NullableTilde<T>
impl<T: Debug> Debug for NullableTilde<T>
Source§impl<'de, T: Deserialize<'de>> Deserialize<'de> for NullableTilde<T>
impl<'de, T: Deserialize<'de>> Deserialize<'de> for NullableTilde<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 NullableTilde<T>
Source§impl<T: PartialEq> PartialEq for NullableTilde<T>
impl<T: PartialEq> PartialEq for NullableTilde<T>
Source§fn eq(&self, other: &NullableTilde<T>) -> bool
fn eq(&self, other: &NullableTilde<T>) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl<T: Serialize> Serialize for NullableTilde<T>
impl<T: Serialize> Serialize for NullableTilde<T>
impl<T: PartialEq> StructuralPartialEq for NullableTilde<T>
Auto Trait Implementations§
impl<T> Freeze for NullableTilde<T>where
T: Freeze,
impl<T> RefUnwindSafe for NullableTilde<T>where
T: RefUnwindSafe,
impl<T> Send for NullableTilde<T>where
T: Send,
impl<T> Sync for NullableTilde<T>where
T: Sync,
impl<T> Unpin for NullableTilde<T>where
T: Unpin,
impl<T> UnsafeUnpin for NullableTilde<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for NullableTilde<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