Skip to main content

Separated

Struct Separated 

Source
pub struct Separated<const SEP: char = ',', A = Same>(/* private fields */);
Expand description

A sequence that is written as text with a separator, like a,b,c.

This is for lists in places where only text fits, like environment variables and command line arguments. When deserializing, a string (or a lexical atom) is split at the separator SEP (a comma by default) and every piece is deserialized with the adapter A (by default Same) as a lexical atom, so numbers and booleans parse. The empty string is an empty sequence. Sequences are accepted as they are (their elements are not split), so the same type still reads arrays from JSON or TOML. Pieces are not trimmed and there is no escaping, see TrimWhitespace to trim them.

When serializing, the elements are joined with the separator into a string in all formats. Elements have to be strings, numbers, booleans or chars. Values that would not read back are an error: an element that contains the separator and a sequence of a single empty string (which would read back as the empty sequence).

Supported are Vec<T>, VecDeque<T>, BTreeSet<T> and HashSet<T>.

use deser::adapters::{Separated, TrimWhitespace};
use deser::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
pub struct Config {
    // `a,b,c`
    #[deser(as = Separated)]
    hosts: Vec<String>,
    // `/usr/bin:/bin`
    #[deser(as = Separated<':'>)]
    search_path: Vec<String>,
    // `80, 443`
    #[deser(as = Separated<',', TrimWhitespace>)]
    ports: Vec<u16>,
}

Trait Implementations§

Source§

impl<'de, T: Ord + Send, A: Deserialize<'de, T>, const SEP: char> Deserialize<'de, BTreeSet<T>> for Separated<SEP, A>

Source§

fn deserialize_into<'out>( out: &'out mut Option<BTreeSet<T>>, state: &mut State, ) -> SinkHandle<'out, 'de>

Creates a sink that deserializes the value into the given slot. Read more
Source§

fn expecting() -> Cow<'static, str>

Returns what the value expects, for error messages. Read more
Source§

fn deserialize_atom( slot: &mut Slot<T, Self>, atom: Atom<'_>, state: &mut State, ) -> Result<(), Error>

Deserializes an atom into the slot. Read more
Source§

fn deserialize_borrowed_atom( slot: &mut Slot<T, Self>, atom: Atom<'de>, state: &mut State, ) -> Result<(), Error>

Deserializes an atom that borrows from the data being deserialized into the slot. Read more
Source§

fn describe_type(d: &mut dyn Describe)

Describes the Rust shape of the type. Read more
Source§

fn initial_value() -> Option<T>

Provides the value of a missing struct field. Read more
Source§

fn deserialize_update<'out>( value: &'out mut T, state: &mut State, ) -> SinkHandle<'out, 'de>

Creates a sink that updates an existing value. Read more
Source§

impl<'de, T: Hash + Eq + Send, H: BuildHasher + Default + Send, A: Deserialize<'de, T>, const SEP: char> Deserialize<'de, HashSet<T, H>> for Separated<SEP, A>

Source§

fn deserialize_into<'out>( out: &'out mut Option<HashSet<T, H>>, state: &mut State, ) -> SinkHandle<'out, 'de>

Creates a sink that deserializes the value into the given slot. Read more
Source§

fn expecting() -> Cow<'static, str>

Returns what the value expects, for error messages. Read more
Source§

fn deserialize_atom( slot: &mut Slot<T, Self>, atom: Atom<'_>, state: &mut State, ) -> Result<(), Error>

Deserializes an atom into the slot. Read more
Source§

fn deserialize_borrowed_atom( slot: &mut Slot<T, Self>, atom: Atom<'de>, state: &mut State, ) -> Result<(), Error>

Deserializes an atom that borrows from the data being deserialized into the slot. Read more
Source§

fn describe_type(d: &mut dyn Describe)

Describes the Rust shape of the type. Read more
Source§

fn initial_value() -> Option<T>

Provides the value of a missing struct field. Read more
Source§

fn deserialize_update<'out>( value: &'out mut T, state: &mut State, ) -> SinkHandle<'out, 'de>

Creates a sink that updates an existing value. Read more
Source§

impl<'de, T: Send, A: Deserialize<'de, T>, const SEP: char> Deserialize<'de, Vec<T>> for Separated<SEP, A>

Source§

fn deserialize_into<'out>( out: &'out mut Option<Vec<T>>, state: &mut State, ) -> SinkHandle<'out, 'de>

Creates a sink that deserializes the value into the given slot. Read more
Source§

fn expecting() -> Cow<'static, str>

Returns what the value expects, for error messages. Read more
Source§

fn deserialize_atom( slot: &mut Slot<T, Self>, atom: Atom<'_>, state: &mut State, ) -> Result<(), Error>

Deserializes an atom into the slot. Read more
Source§

fn deserialize_borrowed_atom( slot: &mut Slot<T, Self>, atom: Atom<'de>, state: &mut State, ) -> Result<(), Error>

Deserializes an atom that borrows from the data being deserialized into the slot. Read more
Source§

fn describe_type(d: &mut dyn Describe)

Describes the Rust shape of the type. Read more
Source§

fn initial_value() -> Option<T>

Provides the value of a missing struct field. Read more
Source§

fn deserialize_update<'out>( value: &'out mut T, state: &mut State, ) -> SinkHandle<'out, 'de>

Creates a sink that updates an existing value. Read more
Source§

impl<'de, T: Send, A: Deserialize<'de, T>, const SEP: char> Deserialize<'de, VecDeque<T>> for Separated<SEP, A>

Source§

fn deserialize_into<'out>( out: &'out mut Option<VecDeque<T>>, state: &mut State, ) -> SinkHandle<'out, 'de>

Creates a sink that deserializes the value into the given slot. Read more
Source§

fn expecting() -> Cow<'static, str>

Returns what the value expects, for error messages. Read more
Source§

fn deserialize_atom( slot: &mut Slot<T, Self>, atom: Atom<'_>, state: &mut State, ) -> Result<(), Error>

Deserializes an atom into the slot. Read more
Source§

fn deserialize_borrowed_atom( slot: &mut Slot<T, Self>, atom: Atom<'de>, state: &mut State, ) -> Result<(), Error>

Deserializes an atom that borrows from the data being deserialized into the slot. Read more
Source§

fn describe_type(d: &mut dyn Describe)

Describes the Rust shape of the type. Read more
Source§

fn initial_value() -> Option<T>

Provides the value of a missing struct field. Read more
Source§

fn deserialize_update<'out>( value: &'out mut T, state: &mut State, ) -> SinkHandle<'out, 'de>

Creates a sink that updates an existing value. Read more
Source§

impl<T, A: Serialize<T>, const SEP: char> Serialize<BTreeSet<T>> for Separated<SEP, A>

Source§

fn serialize<'a>( value: &'a BTreeSet<T>, state: &mut State, ) -> Result<Emit<'a>, Error>

Serializes the value.
Source§

fn finish(value: &T, state: &mut State) -> Result<(), Error>

Invoked after the serialization finished. Read more
Source§

fn is_optional(value: &T) -> bool

Checks if the value represents an optional value. Read more
Source§

fn describe(value: &T, d: &mut dyn Describe)

Describes the Rust shape of the value. Read more
Source§

fn container_shape(value: &T) -> ContainerShape

Returns the shape of the value if it’s a map or sequence. Read more
Source§

impl<T, H, A: Serialize<T>, const SEP: char> Serialize<HashSet<T, H>> for Separated<SEP, A>

Source§

fn serialize<'a>( value: &'a HashSet<T, H>, state: &mut State, ) -> Result<Emit<'a>, Error>

Serializes the value.
Source§

fn finish(value: &T, state: &mut State) -> Result<(), Error>

Invoked after the serialization finished. Read more
Source§

fn is_optional(value: &T) -> bool

Checks if the value represents an optional value. Read more
Source§

fn describe(value: &T, d: &mut dyn Describe)

Describes the Rust shape of the value. Read more
Source§

fn container_shape(value: &T) -> ContainerShape

Returns the shape of the value if it’s a map or sequence. Read more
Source§

impl<T, A: Serialize<T>, const SEP: char> Serialize<Vec<T>> for Separated<SEP, A>

Source§

fn serialize<'a>( value: &'a Vec<T>, state: &mut State, ) -> Result<Emit<'a>, Error>

Serializes the value.
Source§

fn finish(value: &T, state: &mut State) -> Result<(), Error>

Invoked after the serialization finished. Read more
Source§

fn is_optional(value: &T) -> bool

Checks if the value represents an optional value. Read more
Source§

fn describe(value: &T, d: &mut dyn Describe)

Describes the Rust shape of the value. Read more
Source§

fn container_shape(value: &T) -> ContainerShape

Returns the shape of the value if it’s a map or sequence. Read more
Source§

impl<T, A: Serialize<T>, const SEP: char> Serialize<VecDeque<T>> for Separated<SEP, A>

Source§

fn serialize<'a>( value: &'a VecDeque<T>, state: &mut State, ) -> Result<Emit<'a>, Error>

Serializes the value.
Source§

fn finish(value: &T, state: &mut State) -> Result<(), Error>

Invoked after the serialization finished. Read more
Source§

fn is_optional(value: &T) -> bool

Checks if the value represents an optional value. Read more
Source§

fn describe(value: &T, d: &mut dyn Describe)

Describes the Rust shape of the value. Read more
Source§

fn container_shape(value: &T) -> ContainerShape

Returns the shape of the value if it’s a map or sequence. Read more

Auto Trait Implementations§

§

impl<const SEP: char, A> Freeze for Separated<SEP, A>
where PhantomData<fn() -> A>: Freeze,

§

impl<const SEP: char, A> RefUnwindSafe for Separated<SEP, A>
where PhantomData<fn() -> A>: RefUnwindSafe,

§

impl<const SEP: char, A> Send for Separated<SEP, A>
where PhantomData<fn() -> A>: Send,

§

impl<const SEP: char, A> Sync for Separated<SEP, A>
where PhantomData<fn() -> A>: Sync,

§

impl<const SEP: char, A> Unpin for Separated<SEP, A>
where PhantomData<fn() -> A>: Unpin,

§

impl<const SEP: char, A> UnsafeUnpin for Separated<SEP, A>
where PhantomData<fn() -> A>: UnsafeUnpin,

§

impl<const SEP: char, A> UnwindSafe for Separated<SEP, A>
where PhantomData<fn() -> A>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.