pub struct Iterated<I>(/* private fields */);
Expand description
Implementation of Inspect
a type that implements Iterator
with an
item type (K, V)
.
Inspecting this type will respond with a field for each entry in the
iterator, with K
for the field’s name and V
for the field’s value.
Construct with iter_by_key
or iter_by_index
.
Implementations§
source§impl<I, K, V> Iterated<I>
impl<I, K, V> Iterated<I>
sourcepub fn map_key<F, K2>(
self,
f: F,
) -> Iterated<impl Clone + Iterator<Item = (K2, V)>>
pub fn map_key<F, K2>( self, f: F, ) -> Iterated<impl Clone + Iterator<Item = (K2, V)>>
Maps the key of the iterator with f
.
§Example
fn inspect(req: inspect::Request<'_>) {
let v = vec!["foo", "bar", "baz"];
// Responds with { 1: "foo", 2: "bar", 3: "baz" }.
req.respond().field("v", inspect::iter_by_index(&v).map_key(|k| k + 1));
}
sourcepub fn map_value<F, V2>(
self,
f: F,
) -> Iterated<impl Clone + Iterator<Item = (K, V2)>>
pub fn map_value<F, V2>( self, f: F, ) -> Iterated<impl Clone + Iterator<Item = (K, V2)>>
Maps the value of the iterator with f
.
§Example
fn inspect(req: inspect::Request<'_>) {
let v = vec![10, 20, 30];
// Responds with { 0: 20, 1: 40, 2: 60 }.
req.respond().field("v", inspect::iter_by_index(&v).map_value(|v| v * 2));
}
sourcepub fn prefix<'a>(
self,
prefix: &'a str,
) -> Iterated<impl 'a + Clone + Iterator<Item = (String, V)>>where
K: Display + 'a,
I: 'a,
V: 'a,
pub fn prefix<'a>(
self,
prefix: &'a str,
) -> Iterated<impl 'a + Clone + Iterator<Item = (String, V)>>where
K: Display + 'a,
I: 'a,
V: 'a,
Prefixes each key with the string prefix
.
§Example
fn inspect(req: inspect::Request<'_>) {
let v = vec![10, 20, 30];
// Responds with { n0: 10, n1: 20, n2: 30 }.
req.respond().field("v", inspect::iter_by_index(&v).prefix("n"));
}
Trait Implementations§
Auto Trait Implementations§
impl<I> Freeze for Iterated<I>where
I: Freeze,
impl<I> RefUnwindSafe for Iterated<I>where
I: RefUnwindSafe,
impl<I> Send for Iterated<I>where
I: Send,
impl<I> Sync for Iterated<I>where
I: Sync,
impl<I> Unpin for Iterated<I>where
I: Unpin,
impl<I> UnwindSafe for Iterated<I>where
I: 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