Enum yaml_peg::serde::InlineList
source · [−]pub enum InlineList<T> {
List(Vec<T>),
Inline(T),
}
Available on crate feature
serde
only.Expand description
A data type that can support listed items, or inline it if there is single item.
use serde::Deserialize;
use yaml_peg::{node, serde::InlineList};
#[derive(Deserialize)]
struct Content {
img: InlineList<Img>,
}
#[derive(Deserialize)]
struct Img {
src: String,
}
let n_listed = node!({"img" => node!([node!({"src" => "img/1.png"}), node!({"src" => "img/2.png"})])});
let n_inline = node!({"img" => node!({"src" => "img/1.png"})});
let listed = Content::deserialize(n_listed).unwrap();
let inline = Content::deserialize(n_inline).unwrap();
for (i, img) in listed.img.iter().enumerate() {
assert_eq!(format!("img/{}.png", i + 1), img.src);
}
for (i, img) in inline.img.into_iter().enumerate() {
assert_eq!(format!("img/{}.png", i + 1), img.src);
}
Variants
List(Vec<T>)
Listed representation.
Inline(T)
Inline representation.
Implementations
sourceimpl<T> InlineList<T>
impl<T> InlineList<T>
Trait Implementations
sourceimpl<T: Debug> Debug for InlineList<T>
impl<T: Debug> Debug for InlineList<T>
sourceimpl<T> Default for InlineList<T>
impl<T> Default for InlineList<T>
sourceimpl<'de, T> Deserialize<'de> for InlineList<T> where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for InlineList<T> where
T: Deserialize<'de>,
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<T> IntoIterator for InlineList<T>
impl<T> IntoIterator for InlineList<T>
sourceimpl<T: PartialEq> PartialEq<InlineList<T>> for InlineList<T>
impl<T: PartialEq> PartialEq<InlineList<T>> for InlineList<T>
sourcefn eq(&self, other: &InlineList<T>) -> bool
fn eq(&self, other: &InlineList<T>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourceimpl<T> Serialize for InlineList<T> where
T: Serialize,
impl<T> Serialize for InlineList<T> where
T: Serialize,
impl<T: Eq> Eq for InlineList<T>
impl<T> StructuralEq for InlineList<T>
impl<T> StructuralPartialEq for InlineList<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for InlineList<T> where
T: RefUnwindSafe,
impl<T> Send for InlineList<T> where
T: Send,
impl<T> Sync for InlineList<T> where
T: Sync,
impl<T> Unpin for InlineList<T> where
T: Unpin,
impl<T> UnwindSafe for InlineList<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more