inspect_core/inspect.rs
1//! The core [`Inspect`] trait.
2
3use crate::{InspectCx, ValueRef};
4
5/// Provides structured introspection of a Rust value.
6///
7/// This trait allows types to expose their structure and content in a way
8/// that tools, debuggers, and renderers can consume without requiring
9/// specific serialization formats or coupling to UI frameworks.
10///
11/// # Deriving
12///
13/// The recommended way to implement `Inspect` is via the derive macro:
14///
15/// ```ignore
16/// use inspect_rs::Inspect;
17///
18/// #[derive(Inspect)]
19/// struct User {
20/// id: u64,
21/// name: String,
22/// }
23/// ```
24///
25/// # Manual implementation
26///
27/// For types that need custom introspection logic:
28///
29/// ```
30/// use inspect_core::{Inspect, InspectCx, ValueRef, Kind, TypeInfo};
31///
32/// struct Custom(u32);
33///
34/// impl Inspect for Custom {
35/// fn inspect(&self, cx: &mut InspectCx<'_>) -> ValueRef<'_> {
36/// ValueRef::with_type(
37/// Kind::U32(self.0),
38/// TypeInfo::new("Custom"),
39/// )
40/// }
41/// }
42/// ```
43pub trait Inspect {
44 /// Inspect this value and return a borrowed structured representation.
45 ///
46 /// # Parameters
47 ///
48 /// - `cx`: Inspection context containing configuration, limits, and state
49 ///
50 /// # Performance
51 ///
52 /// This method should be cheap to call. Avoid allocating entire trees
53 /// or traversing large collections. Use lazy child enumeration instead.
54 fn inspect(&self, cx: &mut InspectCx<'_>) -> ValueRef<'_>;
55}