Trait inspect::Inspect

source ·
pub trait Inspect {
    // Required method
    fn inspect(&self, req: Request<'_>);
}
Expand description

Trait implemented by objects whose state can be inspected but not mutated.

For most cases, users should use the derive version of Inspect as this will automatically update the implementation as new fields are added.

However there are cases where a user may want to manually implement this trait, such as when an inspection result may require multiple struct fields for a single inspection field. Users should take advantage of Rust’s struct destructuring to introduce compiler errors to keep manual Inspect trait implementations up to date as the struct changes.

§Example

The following code compiles.

struct Foo {
    id: u32,
    more_stuff: usize,
    super_string: String,
}

impl Inspect for Foo {
    fn inspect(&self, req: inspect::Request<'_>) {
        let Foo {
            id,
            more_stuff,
            super_string,
        } = self;

        let mut resp = req.respond();
        resp.hex("id", id);
        resp.field("more_stuff", more_stuff);

        // Only provide the super_string field if id is 2.
        if *id == 2 {
            resp.field("super_string", super_string);
        }
    }
}

However, someone adding a new field to Foo without updating the inspect implementation will no longer compile.

struct Foo {
    id: u32,
    more_stuff: usize,
    super_string: String,
    awesome_new_field: String,
}

impl Inspect for Foo {
    fn inspect(&self, req: inspect::Request<'_>) {
        let Foo {
            id,
            more_stuff,
            super_string,
            // Missing awesome_new_field!
        } = self;

        let mut resp = respond();
        resp.hex("id", id);
        resp.field("more_stuff", more_stuff);

        // Only provide the super_string field if id is 2.
        if id == 2 {
            resp.field("super_string", super_string);
        }
    }
}

Required Methods§

source

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

Inspects the object.

Implementations on Foreign Types§

source§

impl Inspect for bool

source§

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

source§

impl Inspect for f32

source§

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

source§

impl Inspect for f64

source§

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

source§

impl Inspect for i8

source§

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

source§

impl Inspect for i16

source§

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

source§

impl Inspect for i32

source§

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

source§

impl Inspect for i64

source§

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

source§

impl Inspect for isize

source§

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

source§

impl Inspect for str

source§

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

source§

impl Inspect for u8

source§

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

source§

impl Inspect for u16

source§

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

source§

impl Inspect for u32

source§

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

source§

impl Inspect for u64

source§

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

source§

impl Inspect for usize

source§

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

source§

impl Inspect for CString

source§

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

source§

impl Inspect for String

source§

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

source§

impl Inspect for Vec<u8>

source§

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

source§

impl Inspect for CStr

source§

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

source§

impl Inspect for Arguments<'_>

source§

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

source§

impl Inspect for AtomicBool

source§

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

source§

impl Inspect for AtomicI8

source§

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

source§

impl Inspect for AtomicI16

source§

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

source§

impl Inspect for AtomicI32

source§

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

source§

impl Inspect for AtomicI64

source§

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

source§

impl Inspect for AtomicIsize

source§

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

source§

impl Inspect for AtomicU8

source§

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

source§

impl Inspect for AtomicU16

source§

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

source§

impl Inspect for AtomicU32

source§

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

source§

impl Inspect for AtomicU64

source§

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

source§

impl Inspect for AtomicUsize

source§

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

source§

impl Inspect for File

source§

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

source§

impl Inspect for NonZeroI8

source§

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

source§

impl Inspect for NonZeroI16

source§

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

source§

impl Inspect for NonZeroI32

source§

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

source§

impl Inspect for NonZeroI64

source§

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

source§

impl Inspect for NonZeroIsize

source§

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

source§

impl Inspect for NonZeroU8

source§

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

source§

impl Inspect for NonZeroU16

source§

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

source§

impl Inspect for NonZeroU32

source§

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

source§

impl Inspect for NonZeroU64

source§

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

source§

impl Inspect for NonZeroUsize

source§

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

source§

impl Inspect for [u8]

source§

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

source§

impl<T> Inspect for *const T

source§

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

source§

impl<T> Inspect for *mut T

source§

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

source§

impl<T: Inspect + ?Sized> Inspect for &T

source§

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

source§

impl<T: Inspect + ?Sized> Inspect for &mut T

source§

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

source§

impl<T: Inspect + ?Sized> Inspect for Box<T>

source§

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

source§

impl<T: Inspect + ?Sized> Inspect for Rc<T>

source§

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

source§

impl<T: Inspect + ?Sized> Inspect for Arc<T>

source§

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

source§

impl<T: Inspect + ?Sized> Inspect for Mutex<T>

source§

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

source§

impl<T: Inspect + ?Sized> Inspect for RwLock<T>

source§

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

source§

impl<T: Inspect> Inspect for Option<T>

source§

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

source§

impl<T: Inspect> Inspect for Wrapping<T>

source§

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

source§

impl<T: Inspect> Inspect for OnceLock<T>

source§

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

source§

impl<T: ?Sized + Inspect + ToOwned> Inspect for Cow<'_, T>

source§

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

source§

impl<const N: usize> Inspect for [u8; N]

source§

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

Implementors§

source§

impl Inspect for AsBinary<u8>

source§

impl Inspect for AsBinary<u16>

source§

impl Inspect for AsBinary<u32>

source§

impl Inspect for AsBinary<u64>

source§

impl Inspect for AsBinary<usize>

source§

impl Inspect for AsCounter<u8>

source§

impl Inspect for AsCounter<u16>

source§

impl Inspect for AsCounter<u32>

source§

impl Inspect for AsCounter<u64>

source§

impl Inspect for AsCounter<usize>

source§

impl Inspect for AsHex<u8>

source§

impl Inspect for AsHex<u16>

source§

impl Inspect for AsHex<u32>

source§

impl Inspect for AsHex<u64>

source§

impl Inspect for AsHex<usize>

source§

impl Inspect for AtomicMut<&AtomicBool>

source§

impl Inspect for AtomicMut<&AtomicI8>

source§

impl Inspect for AtomicMut<&AtomicI16>

source§

impl Inspect for AtomicMut<&AtomicI32>

source§

impl Inspect for AtomicMut<&AtomicI64>

source§

impl Inspect for AtomicMut<&AtomicIsize>

source§

impl Inspect for AtomicMut<&AtomicU8>

source§

impl Inspect for AtomicMut<&AtomicU16>

source§

impl Inspect for AtomicMut<&AtomicU32>

source§

impl Inspect for AtomicMut<&AtomicU64>

source§

impl Inspect for AtomicMut<&AtomicUsize>

source§

impl Inspect for Value

source§

impl<F> Inspect for Adhoc<F>
where F: Fn(Request<'_>),

source§

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

source§

impl<T> Inspect for AsBinary<Option<T>>
where for<'a> AsBinary<&'a T>: Inspect,

source§

impl<T> Inspect for AsBytes<T>
where T: Clone + IntoIterator, Vec<u8>: Extend<T::Item>,

source§

impl<T> Inspect for AsHex<Option<T>>
where for<'a> AsHex<&'a T>: Inspect,

source§

impl<T> Inspect for AsHex<Wrapping<T>>
where for<'a> AsHex<&'a T>: Inspect,

source§

impl<T: Clone> Inspect for AsBinary<&T>
where AsBinary<T>: Inspect,

source§

impl<T: Clone> Inspect for AsCounter<&T>
where AsCounter<T>: Inspect,

source§

impl<T: Clone> Inspect for AsHex<&T>
where AsHex<T>: Inspect,

source§

impl<T: Debug> Inspect for AsDebug<T>

source§

impl<T: Display> Inspect for AsDisplay<T>