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