Skip to main content

Explorer

Struct Explorer 

Source
pub struct Explorer<'a> { /* private fields */ }
Expand description

A renderable view of a document tree.

Scalars reuse core’s JSON styles, keys json.key, XML attributes data.attribute; YAML anchors and aliases show as dim &name / *name badges and INI/dotenv comments as a dim # comment. Every line is cut to the available width: long strings shrink first (keeping their quotes), then the line ends in …, so nothing wraps.

use rich::Console;
use rich_ext::data::{parse, Explorer, Format};

let node = parse(Format::Json, r#"{"a": {"b": 1, "c": 2}, "d": [1, 2, 3]}"#).unwrap();
let explorer = Explorer::new(&node).max_depth(1).root_label("doc");
let out = Console::builder().width(40).build().render_export(&explorer);
assert_eq!(out, "doc\n├── a: {…} 2 keys\n└── d: […] 3 items\n");

Implementations§

Source§

impl<'a> Explorer<'a>

Source

pub fn new(node: impl Into<Cow<'a, Node>>) -> Self

Explore an owned or borrowed node.

Source

pub fn max_depth(self, depth: usize) -> Self

Fold containers this deep (the root is depth 0) to a summary like {…} 3 keys.

Source

pub fn max_length(self, length: usize) -> Self

Show at most this many children per container, then … N more.

Source

pub fn max_string(self, length: usize) -> Self

Cut strings to this many characters (with …). Strings are also cut to the available width regardless.

Source

pub fn show_paths(self, show: bool) -> Self

Append each leaf’s path, dim.

Source

pub fn show_types(self, show: bool) -> Self

Append each node’s type (str, int, map, …), dim.

Source

pub fn fold(self, path: Path) -> Self

Fold the container at path.

Source

pub fn highlight(self, path: Path, style: Style) -> Self

Style the tree line of the node at path, such as the selection of a data::transform::Highlight. The table view ignores it.

Source

pub fn root_label(self, label: impl Into<String>) -> Self

The root line’s label (default: the root’s summary).

Source

pub fn view(self, view: View) -> Self

Tree or table.

Source

pub fn node(&self) -> &Node

The node being explored.

Trait Implementations§

Source§

impl<'a> Clone for Explorer<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Explorer<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Renderable for Explorer<'_>

Source§

fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>

Source§

fn measure(&self, console: &Console, options: &ConsoleOptions) -> Measurement

The (minimum, maximum) cell width this renderable wants. The default assumes the renderable fills the available width (e.g. Panel, Table); Text overrides it with its content width so the top-level print path can shrink to fit. Port of __rich_measure__ / Measurement.get.
Source§

fn fit_to_measurement(&self) -> bool

Whether a top-level Console::print shrinks this renderable to its measured width. Upstream renders every top-level renderable at the full console width, so the default is false; an extension may opt in.
Source§

fn vertical(&self) -> Option<VerticalAlign>

The vertical alignment a Table cell holding this renderable uses in place of its column’s. Upstream reads getattr(renderable, "vertical", None); Align sets it.

Auto Trait Implementations§

§

impl<'a> Freeze for Explorer<'a>

§

impl<'a> RefUnwindSafe for Explorer<'a>

§

impl<'a> Send for Explorer<'a>

§

impl<'a> Sync for Explorer<'a>

§

impl<'a> Unpin for Explorer<'a>

§

impl<'a> UnsafeUnpin for Explorer<'a>

§

impl<'a> UnwindSafe for Explorer<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more