Response

Struct Response 

Source
pub struct Response<'a> { /* private fields */ }
Expand description

A type used to build an inspection response.

Implementations§

Source§

impl Response<'_>

Source

pub fn field<T>(&mut self, name: &str, value: T) -> &mut Self
where T: Inspect,

Adds a field to the response.

fn inspect_data(a: u32, b: &str, c: bool, maybe: Option<u32>, req: Request) {
    req.respond()
       .field("a", a)
       .field("b", b)
       .field("c", c)
       .field("maybe", maybe)
       .field("computed", format_args!("{a}-{b}"));
}
Source

pub fn sensitivity_field<T>( &mut self, name: &str, sensitivity: SensitivityLevel, value: T, ) -> &mut Self
where T: Inspect,

Adds a field to the response with a SensitivityLevel.

Source

pub fn hex<T>(&mut self, name: &str, value: T) -> &mut Self
where T: Inspect,

Adds a hexadecimal field to the response.

Source

pub fn counter<T>(&mut self, name: &str, value: T) -> &mut Self
where T: Inspect,

Adds a counter field to the response.

Source

pub fn sensitivity_counter<T>( &mut self, name: &str, sensitivity: SensitivityLevel, value: T, ) -> &mut Self
where T: Inspect,

Adds a counter field to the response.

This is a convenience method for sensitivity_field(name, sensitivity, Value::counter(value)).

Source

pub fn binary<T>(&mut self, name: &str, value: T) -> &mut Self
where T: Inspect,

Adds a binary field to the response.

This is a convenience method for field(name, Value::binary(value)).

Source

pub fn display(&mut self, name: &str, value: &impl Display) -> &mut Self

Adds a string field that implements core::fmt::Display.

This is a convenience method for field_with(name, || value.to_string()). It lazily allocates the string only when the inspector requests it, so it is more efficient than using format! or to_string().

fn inspect_data(path: &Path, id: u32, req: Request) {
    req.respond().display("path", &path.display());
}
Source

pub fn display_debug(&mut self, name: &str, value: &impl Debug) -> &mut Self

Adds a string field that implements core::fmt::Debug.

This is a convenience method for field(name, format_args!("{value:?}")).

Take care not to overuse this. This is best used for fields that have a short or natural Debug implementation, such as dataless enums. If your field is an aggregate type whose Debug implementation has a complicated structure, consider implementing Inspect on the type and calling field.

Source

pub fn field_with<F, V>(&mut self, name: &str, f: F) -> &mut Self
where F: FnOnce() -> V, V: Inspect,

Adds a field to the response, calling f to get its value.

Source

pub fn sensitivity_field_with<F, V>( &mut self, name: &str, sensitivity: SensitivityLevel, f: F, ) -> &mut Self
where F: FnOnce() -> V, V: Inspect,

Adds a field to the response with a SensitivityLevel, calling f to get its value.

Source

pub fn field_mut<T>(&mut self, name: &str, value: &mut T) -> &mut Self
where T: InspectMut + ?Sized,

Adds a mutable field to the response.

Source

pub fn sensitivity_field_mut<T>( &mut self, name: &str, sensitivity: SensitivityLevel, value: &mut T, ) -> &mut Self
where T: InspectMut + ?Sized,

Adds a mutable field to the response with a SensitivityLevel.

Source

pub fn field_mut_with<F, V, E>(&mut self, name: &str, f: F) -> &mut Self
where F: FnOnce(Option<&str>) -> Result<V, E>, V: Into<ValueKind>, E: Into<Box<dyn Error + Send + Sync>>,

Adds a mutable field with custom get/update function.

Source

pub fn fields<I, N, C>(&mut self, name: &str, children: I) -> &mut Self
where I: Iterator<Item = (N, C)>, N: ToString, C: Inspect,

Inspects a list of children objects as children of the node name.

Each element of children should be a tuple (child_name, child). child_name must be convertible to a string.


struct Child(u32);
impl Inspect for Child {
    fn inspect(&self, req: Request) {
        req.respond().field("x", self.0);
    }
}

struct Parent(Vec<Child>);
impl Inspect for Parent {
    fn inspect(&self, req: Request) {
        req.respond().fields("children", self.0.iter().enumerate());
    }
}

assert_eq!(
    inspect(
        "",
        &Parent(vec![Child(5), Child(12)]),
    )
    .results()
    .to_string(),
    r#"{children: {0: {x: 5}, 1: {x: 12}}}"#
);
Source

pub fn fields_mut<I, N, C>(&mut self, name: &str, children: I) -> &mut Self
where I: Iterator<Item = (N, C)>, N: ToString, C: InspectMut,

Inspects a list of children objects as children of the node name.

Each element of children should be a tuple (child_name, child). child_name must be convertible to a string.

struct Child(u32);
impl InspectMut for Child {
    fn inspect_mut(&mut self, req: Request) {
        req.respond().field("x", self.0);
    }
}

struct Parent(Vec<Child>);
impl InspectMut for Parent {
    fn inspect_mut(&mut self, req: Request) {
        req.respond().fields_mut("children", self.0.iter_mut().enumerate());
    }
}

assert_eq!(
    inspect(
        "",
        &mut Parent(vec![Child(5), Child(12)]),
    )
    .results()
    .to_string(),
    r#"{children: {0: {x: 5}, 1: {x: 12}}}"#
);
Source

pub fn child<F: FnOnce(Request<'_>)>(&mut self, name: &str, f: F) -> &mut Self

Adds a child node to the inspection response.

If name is empty, then the results of the inspection are merged into this node.

Source

pub fn sensitivity_child<F: FnOnce(Request<'_>)>( &mut self, name: &str, sensitivity: SensitivityLevel, f: F, ) -> &mut Self

Adds a child node to the inspection response with a SensitivityLevel.

If name is empty, then the results of the inspection are merged into this node.

Source

pub fn merge(&mut self, child: impl InspectMut) -> &mut Self

Inspects an object and merges its responses into this node without creating a child node.

Source

pub fn parent_sensitivity(&self) -> SensitivityLevel

Gets the sensitivity level of the parent node of this request. This is useful for wrappers around fields that wish to inherit the sensitivity level of their parent node.

Auto Trait Implementations§

§

impl<'a> Freeze for Response<'a>

§

impl<'a> !RefUnwindSafe for Response<'a>

§

impl<'a> Send for Response<'a>

§

impl<'a> Sync for Response<'a>

§

impl<'a> Unpin for Response<'a>

§

impl<'a> !UnwindSafe for Response<'a>

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.

§

impl<T> Instrument for T

§

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

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

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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