pub struct SingleQuoted<T>(pub T);Expand description
Force a string value to be emitted in a single-quoted style. This provides additional safety constraints, as serializer rejects control characters and other values that require double-quoted string escaping.
This wrapper is transparent during deserialization: the inner value is
deserialized normally and placed into SingleQuoted<T>. SingleQuoted<T> implements
Serde traits only for string-like T values.
Serialization fails if the value cannot be represented safely in YAML single-quoted style.
use serde::Serialize;
use serde_saphyr::SingleQuoted;
#[derive(Serialize)]
struct Config {
value: SingleQuoted<String>,
}
let cfg = Config { value: SingleQuoted("plain text".to_string()) };
let yaml = serde_saphyr::to_string(&cfg).unwrap();
assert_eq!(yaml, "value: 'plain text'\n");Tuple Fields§
§0: TTrait Implementations§
Source§impl<T: Clone> Clone for SingleQuoted<T>
impl<T: Clone> Clone for SingleQuoted<T>
Source§fn clone(&self) -> SingleQuoted<T>
fn clone(&self) -> SingleQuoted<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 SingleQuoted<T>
impl<T: Debug> Debug for SingleQuoted<T>
Source§impl<'de, T> Deserialize<'de> for SingleQuoted<T>
impl<'de, T> Deserialize<'de> for SingleQuoted<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 SingleQuoted<T>
Source§impl<T: PartialEq> PartialEq for SingleQuoted<T>
impl<T: PartialEq> PartialEq for SingleQuoted<T>
impl<T: PartialEq> StructuralPartialEq for SingleQuoted<T>
Auto Trait Implementations§
impl<T> Freeze for SingleQuoted<T>where
T: Freeze,
impl<T> RefUnwindSafe for SingleQuoted<T>where
T: RefUnwindSafe,
impl<T> Send for SingleQuoted<T>where
T: Send,
impl<T> Sync for SingleQuoted<T>where
T: Sync,
impl<T> Unpin for SingleQuoted<T>where
T: Unpin,
impl<T> UnsafeUnpin for SingleQuoted<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for SingleQuoted<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