inspect-rs 0.1.0

Universal introspection for Rust
Documentation
//! # inspect-rs
//!
//! Universal introspection for Rust.
//!
//! `inspect-rs` provides a lightweight protocol for structured introspection
//! of Rust values without coupling to debuggers, serializers, or specific
//! UI frameworks.
//!
//! ## Quick Start
//!
//! ```
//! use inspect_rs::Inspect;
//!
//! #[derive(Inspect)]
//! struct User {
//!     id: u64,
//!     name: String,
//!     active: bool,
//! }
//!
//! let user = User {
//!     id: 42,
//!     name: "Alice".to_string(),
//!     active: true,
//! };
//!
//! let mut cx = inspect_rs::InspectCx::new();
//! let inspected = user.inspect(&mut cx);
//!
//! println!("{}", inspect_rs::format_tree(&inspected));
//! ```
//!
//! ## Design Principles
//!
//! - **Lazy**: Values are not eagerly traversed
//! - **Zero-copy**: Borrows from original values where possible
//! - **Safe**: Handles cycles, respects limits, protects secrets
//! - **Minimal**: Zero runtime dependencies in core
//! - **Semantic Styling**: Restrained, accessible, terminal-aware colored output

pub use inspect_core::{
    Capability, Children, DepthGuard, FieldInfo, Inspect, InspectCx, InspectError, InspectLimits,
    InspectPath, InspectResult, Kind, PathSegment, Sensitivity, TypeInfo, ValueRef, VariantInfo,
};
pub use inspect_derive::Inspect;
#[cfg(feature = "color")]
pub use inspect_format::{Ansi256Color, Color, Effects, Reset, RgbColor};
pub use inspect_format::{
    AnsiColor, ColorChoice, ColorLevel, Style, StyleRole, Theme, TreeConfig, TreeFormatter,
};

/// Format an inspected value as a tree with automatic terminal color detection.
///
/// If stdout is a TTY and environment variables allow it, semantic colors are applied.
/// If output is redirected to a file or pipe, colors are automatically omitted.
///
/// # Example
///
/// ```
/// use inspect_rs::{Inspect, InspectCx, format_tree};
///
/// let value = vec![1, 2, 3];
/// let mut cx = InspectCx::new();
/// let inspected = value.inspect(&mut cx);
///
/// println!("{}", format_tree(&inspected));
/// ```
pub fn format_tree(value: &ValueRef<'_>) -> String {
    TreeFormatter::new().format(value)
}

/// Format an inspected value as a compact tree.
pub fn format_tree_compact(value: &ValueRef<'_>) -> String {
    TreeFormatter::with_config(TreeConfig::compact()).format(value)
}

/// Format an inspected value as a tree with ANSI color codes explicitly enabled.
pub fn format_tree_colored(value: &ValueRef<'_>) -> String {
    TreeFormatter::new().format_colored(value)
}

/// Format an inspected value as a tree with ANSI color codes explicitly disabled.
pub fn format_tree_plain(value: &ValueRef<'_>) -> String {
    TreeFormatter::new().format_plain(value)
}

/// Format an inspected value as a tree using a custom [`TreeConfig`].
pub fn format_tree_with(value: &ValueRef<'_>, config: TreeConfig) -> String {
    TreeFormatter::with_config(config).format(value)
}