Struct serde_with::rust::StringWithSeparator [] [src]

pub struct StringWithSeparator<Sep>(_);

De/Serialize a delimited collection using Display and FromStr implementation

You can define an arbitrary seperator, by specifying a type which implements Separator. Some common ones, like space and comma are already predefined and you can find them here.

An empty string deserializes as an empty collection.

Examples

use serde_with::{CommaSeparator, SpaceSeparator};
use std::collections::BTreeSet;

#[derive(Deserialize, Serialize)]
struct A {
    #[serde(with = "serde_with::rust::StringWithSeparator::<SpaceSeparator>")]
    tags: Vec<String>,
    #[serde(with = "serde_with::rust::StringWithSeparator::<CommaSeparator>")]
    more_tags: BTreeSet<String>,
}

let v: A = serde_json::from_str(r##"{
    "tags": "#hello #world",
    "more_tags": "foo,bar,bar"
}"##).unwrap();
assert_eq!(vec!["#hello", "#world"], v.tags);
assert_eq!(2, v.more_tags.len());

let x = A {
    tags: vec!["1".to_string(), "2".to_string(), "3".to_string()],
    more_tags: BTreeSet::new(),
};
assert_eq!(r#"{"tags":"1 2 3","more_tags":""}"#, serde_json::to_string(&x).unwrap());

Methods

impl<Sep> StringWithSeparator<Sep> where
    Sep: Separator
[src]

[src]

[src]

Trait Implementations

impl<Sep: Copy> Copy for StringWithSeparator<Sep>
[src]

impl<Sep: Clone> Clone for StringWithSeparator<Sep>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<Sep: Eq> Eq for StringWithSeparator<Sep>
[src]

impl<Sep: PartialEq> PartialEq for StringWithSeparator<Sep>
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl<Sep: Ord> Ord for StringWithSeparator<Sep>
[src]

[src]

This method returns an Ordering between self and other. Read more

1.21.0
[src]

Compares and returns the maximum of two values. Read more

1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl<Sep: PartialOrd> PartialOrd for StringWithSeparator<Sep>
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

[src]

This method tests less than (for self and other) and is used by the < operator. Read more

[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<Sep: Hash> Hash for StringWithSeparator<Sep>
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl<Sep: Debug> Debug for StringWithSeparator<Sep>
[src]

[src]

Formats the value using the given formatter. Read more

impl<Sep: Default> Default for StringWithSeparator<Sep>
[src]

[src]

Returns the "default value" for a type. Read more

Auto Trait Implementations

impl<Sep> Send for StringWithSeparator<Sep> where
    Sep: Send

impl<Sep> Sync for StringWithSeparator<Sep> where
    Sep: Sync