fast_rich/
inspect.rs

1//! Introspection tools for debugging.
2
3use crate::console::Console;
4use crate::panel::Panel;
5
6use std::fmt::Debug;
7
8/// Configuration for the inspect function.
9#[derive(Debug, Clone, Default)]
10pub struct InspectConfig {
11    /// Show detailed documentation (mock).
12    pub help: bool,
13    /// Show methods (mock).
14    pub methods: bool,
15}
16
17/// Inspect an object and print a report to the console.
18///
19/// In Rust, this relies on the `Debug` trait.
20pub fn inspect<T: Debug>(obj: &T, config: InspectConfig) {
21    let console = Console::new();
22    let debug_str = format!("{:#?}", obj);
23
24    // Header
25    let type_name = std::any::type_name::<T>();
26    let title = format!("Inspect: [bold cyan]{}[/]", type_name);
27
28    let mut chunks = Vec::new();
29    chunks.push(format!("Type: [green]{}[/]", type_name));
30
31    if config.help {
32        chunks.push(
33            "\n[dim]Docstrings are not available in Rust runtime introspection.[/dim]".to_string(),
34        );
35    }
36
37    chunks.push(format!("\n[bold]Value:[/]\n{}", debug_str));
38
39    let content = chunks.join("\n");
40    let panel = Panel::new(crate::markup::parse(&content))
41        .title(&title)
42        .style(crate::style::Style::new().foreground(crate::style::Color::Blue));
43
44    console.print_renderable(&panel);
45}