pub struct OneOrMany<T>(/* private fields */);Expand description
A value that may serialize as either a single T or as an ordered array
of T.
On the wire an empty OneOrMany is emitted as an empty array, a single
entry as a bare value, and multiple entries as a JSON array.
§Examples
let one: OneOrMany<String> =
serde_json::from_str(r#""Hello""#).unwrap();
assert_eq!(one.as_slice(), &["Hello".to_owned()]);
let many: OneOrMany<String> =
serde_json::from_str(r#"["A", "B"]"#).unwrap();
assert_eq!(many.len(), 2);Implementations§
Trait Implementations§
Source§impl<'de, T: Deserialize<'de>> Deserialize<'de> for OneOrMany<T>
impl<'de, T: Deserialize<'de>> Deserialize<'de> for OneOrMany<T>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl<T: Eq> Eq for OneOrMany<T>
Source§impl<T> FromIterator<T> for OneOrMany<T>
impl<T> FromIterator<T> for OneOrMany<T>
Source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Creates a value from an iterator. Read more
Source§impl<T> IntoIterator for OneOrMany<T>
impl<T> IntoIterator for OneOrMany<T>
Source§impl<'a, T> IntoIterator for &'a OneOrMany<T>
impl<'a, T> IntoIterator for &'a OneOrMany<T>
Source§impl<'a, T> IntoIterator for &'a mut OneOrMany<T>
impl<'a, T> IntoIterator for &'a mut OneOrMany<T>
Source§impl<T: PartialEq> PartialEq for OneOrMany<T>
impl<T: PartialEq> PartialEq for OneOrMany<T>
impl<T: PartialEq> StructuralPartialEq for OneOrMany<T>
Auto Trait Implementations§
impl<T> Freeze for OneOrMany<T>
impl<T> RefUnwindSafe for OneOrMany<T>where
T: RefUnwindSafe,
impl<T> Send for OneOrMany<T>where
T: Send,
impl<T> Sync for OneOrMany<T>where
T: Sync,
impl<T> Unpin for OneOrMany<T>where
T: Unpin,
impl<T> UnsafeUnpin for OneOrMany<T>
impl<T> UnwindSafe for OneOrMany<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.