Expand description
#[derive(Introspect)] — auto-implements kanshou::Introspect
for a struct whose pub fields are each independently queryable.
§Default behavior
- Every
pubnamed field becomes a top-level path leaf. A queryQuery { path: ["field_name"] }returnsserde_json::to_value(&self.field_name). - Tuple structs, unit structs, and enums are unsupported (compile
error). Consumers with non-struct shapes hand-write
Introspect.
§Field attributes
Per-field #[introspect(...)] modifies the leaf shape:
#[introspect(skip)]— exclude from the query surface. Useful for internal channels, abort handles, or anything the operator shouldn’t see.#[introspect(load)]— call.load(Ordering::Relaxed)before serializing. ForAtomicU64/AtomicUsize/etc. so the wire shape is a number, not the atomic struct’s debug print.#[introspect(nested)]— the field itself implementsIntrospect; nested path elements walk into it. Without this attribute,queryon["field_name", "subfield"]returnsQueryError::UnknownField. With it, the rest of the path recurses.#[introspect(name = "wire_name")]— expose the field under a different name on the wire than the Rust identifier. Mirrors#[serde(rename = "...")]. Lets consumer apps stabilize a public API even when the internal field shape evolves.
§Example
ⓘ
use std::sync::atomic::AtomicU64;
use kanshou::Introspect;
#[derive(Introspect)]
pub struct AppState {
pub sessions: Vec<String>,
#[introspect(load)]
pub frame_count: AtomicU64,
#[introspect(nested)]
pub config: Config,
#[introspect(skip)]
internal: tokio::sync::mpsc::Sender<()>,
}
#[derive(Introspect)]
pub struct Config {
pub shell: String,
pub width: u32,
}Derive Macros§
- Introspect
- Auto-implement
kanshou::Introspectfor a struct with namedpubfields. See module docs for attribute reference.