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]
Sep: Separator,
pub fn serialize<S, T, V>(values: T, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer,
T: IntoIterator<Item = V>,
V: Display,
[src]
S: Serializer,
T: IntoIterator<Item = V>,
V: Display,
pub fn deserialize<'de, D, T, V>(deserializer: D) -> Result<T, D::Error> where
D: Deserializer<'de>,
T: FromIterator<V>,
V: FromStr,
V::Err: Display,
[src]
D: Deserializer<'de>,
T: FromIterator<V>,
V: FromStr,
V::Err: Display,
Trait Implementations
impl<Sep: Copy> Copy for StringWithSeparator<Sep>
[src]
impl<Sep: Clone> Clone for StringWithSeparator<Sep>
[src]
fn clone(&self) -> StringWithSeparator<Sep>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
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]
fn eq(&self, __arg_0: &StringWithSeparator<Sep>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &StringWithSeparator<Sep>) -> bool
[src]
This method tests for !=
.
impl<Sep: Ord> Ord for StringWithSeparator<Sep>
[src]
fn cmp(&self, __arg_0: &StringWithSeparator<Sep>) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
impl<Sep: PartialOrd> PartialOrd for StringWithSeparator<Sep>
[src]
fn partial_cmp(&self, __arg_0: &StringWithSeparator<Sep>) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &StringWithSeparator<Sep>) -> bool
[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &StringWithSeparator<Sep>) -> bool
[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &StringWithSeparator<Sep>) -> bool
[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &StringWithSeparator<Sep>) -> bool
[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]
fn hash<__HSep: Hasher>(&self, __arg_0: &mut __HSep)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<Sep: Debug> Debug for StringWithSeparator<Sep>
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<Sep: Default> Default for StringWithSeparator<Sep>
[src]
fn default() -> StringWithSeparator<Sep>
[src]
Returns the "default value" for a type. Read more
Auto Trait Implementations
impl<Sep> Send for StringWithSeparator<Sep> where
Sep: Send,
Sep: Send,
impl<Sep> Sync for StringWithSeparator<Sep> where
Sep: Sync,
Sep: Sync,