pub struct Each<U, Iterator>where
Iterator: IntoIterator<Item = U>,{
pub items: Iterator,
}
Expand description
A list of items that can be appended into a Document
. For each item in
items
, the callback is invoked, and its return value is appended to
the document.
§Example
struct Point(i32, i32);
let items = vec![Point(10, 20), Point(5, 10), Point(6, 42)];
let document = Document::with(Each(
&items,
|item, doc| doc.add(Line("Point(".add(item.0).add(",").add(item.1).add(")")))
));
assert_eq!(document.to_string()?, "Point(10,20)\nPoint(5,10)\nPoint(6,42)\n");
And with the tree!
macro:
struct Point(i32, i32);
let items = vec![Point(10, 20), Point(5, 10), Point(6, 42)];
let document = tree! {
<Each items={items} as |item| {
<Line as {
"Point(" {item.0} "," {item.1} ")"
}>
}>
};
assert_eq!(document.to_string()?, "Point(10,20)\nPoint(5,10)\nPoint(6,42)\n");
Fields§
§items: Iterator
Trait Implementations§
Source§impl<U, I> From<I> for Each<U, I>where
I: IntoIterator<Item = U>,
impl<U, I> From<I> for Each<U, I>where
I: IntoIterator<Item = U>,
Source§impl<U, Iterator> IterBlockComponent for Each<U, Iterator>where
Iterator: IntoIterator<Item = U>,
impl<U, Iterator> IterBlockComponent for Each<U, Iterator>where
Iterator: IntoIterator<Item = U>,
Auto Trait Implementations§
impl<U, Iterator> Freeze for Each<U, Iterator>where
Iterator: Freeze,
impl<U, Iterator> RefUnwindSafe for Each<U, Iterator>where
Iterator: RefUnwindSafe,
impl<U, Iterator> Send for Each<U, Iterator>where
Iterator: Send,
impl<U, Iterator> Sync for Each<U, Iterator>where
Iterator: Sync,
impl<U, Iterator> Unpin for Each<U, Iterator>where
Iterator: Unpin,
impl<U, Iterator> UnwindSafe for Each<U, Iterator>where
Iterator: 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