Struct inspect::Iterated

source ·
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>
where I: Clone + Iterator<Item = (K, V)>,

source

pub fn map_key<F, K2>( self, f: F, ) -> Iterated<impl Clone + Iterator<Item = (K2, V)>>
where F: Clone + FnMut(K) -> K2,

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));
}
source

pub fn map_value<F, V2>( self, f: F, ) -> Iterated<impl Clone + Iterator<Item = (K, V2)>>
where F: Clone + FnMut(V) -> 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));
}
source

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§

source§

impl<I: Default> Default for Iterated<I>

source§

fn default() -> Iterated<I>

Returns the “default value” for a type. Read more
source§

impl<I, K, V> Inspect for Iterated<I>
where I: Clone + Iterator<Item = (K, V)>, K: ToString, V: Inspect,

source§

fn inspect(&self, req: Request<'_>)

Inspects the object.

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T, U> Upcast<U> for T
where U: Downcast<T>,