Struct serde_with::rust::StringWithSeparator [−][src]
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());
Implementations
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,
Serialize collection into a string with separator symbol
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,
Deserialize a collection from a string with separator symbol
Trait Implementations
impl<Sep: Clone> Clone for StringWithSeparator<Sep>
[src]
fn clone(&self) -> StringWithSeparator<Sep>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<Sep: Copy> Copy for StringWithSeparator<Sep>
[src]
impl<Sep: Debug> Debug for StringWithSeparator<Sep>
[src]
impl<Sep: Default> Default for StringWithSeparator<Sep>
[src]
fn default() -> StringWithSeparator<Sep>
[src]
impl<Sep: Eq> Eq for StringWithSeparator<Sep>
[src]
impl<Sep: Hash> Hash for StringWithSeparator<Sep>
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<Sep: Ord> Ord for StringWithSeparator<Sep>
[src]
fn cmp(&self, other: &StringWithSeparator<Sep>) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<Sep: PartialEq> PartialEq<StringWithSeparator<Sep>> for StringWithSeparator<Sep>
[src]
fn eq(&self, other: &StringWithSeparator<Sep>) -> bool
[src]
fn ne(&self, other: &StringWithSeparator<Sep>) -> bool
[src]
impl<Sep: PartialOrd> PartialOrd<StringWithSeparator<Sep>> for StringWithSeparator<Sep>
[src]
fn partial_cmp(&self, other: &StringWithSeparator<Sep>) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<Sep> StructuralEq for StringWithSeparator<Sep>
[src]
impl<Sep> StructuralPartialEq for StringWithSeparator<Sep>
[src]
Auto Trait Implementations
impl<Sep> RefUnwindSafe for StringWithSeparator<Sep> where
Sep: RefUnwindSafe,
Sep: RefUnwindSafe,
impl<Sep> Send for StringWithSeparator<Sep> where
Sep: Send,
Sep: Send,
impl<Sep> Sync for StringWithSeparator<Sep> where
Sep: Sync,
Sep: Sync,
impl<Sep> Unpin for StringWithSeparator<Sep> where
Sep: Unpin,
Sep: Unpin,
impl<Sep> UnwindSafe for StringWithSeparator<Sep> where
Sep: UnwindSafe,
Sep: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,