Skip to main content

Tree

Struct Tree 

Source
pub struct Tree { /* private fields */ }
Expand description

A foldable, editable JSON/YAML value tree with a cursor and undo history.

Implementations§

Source§

impl Tree

Source

pub fn from_text(text: &str, format: Format) -> Result<Self, String>

Parse text as JSON or YAML into a value tree. YAML’s parser also accepts JSON.

§Errors

Returns the parser’s own message (line/column included) when text does not parse, instead of discarding it (Run H, T543: this used to return a bare Option, so the caller could only show a static “not valid JSON or YAML” with no indication of what was actually wrong or where).

Source

pub fn format(&self) -> Format

The chosen format.

Source

pub fn row_count(&self) -> usize

Number of visible rows.

Source

pub fn sel(&self) -> usize

The selected row index.

Source

pub fn scroll(&self) -> usize

The first visible row (scroll offset).

Source

pub fn is_dirty(&self) -> bool

Whether there are unsaved edits.

Source

pub fn is_editing(&self) -> bool

Whether a scalar is currently being edited.

Source

pub fn edit_buffer(&self) -> &str

The in-progress edit text (valid while Tree::is_editing).

Source

pub fn depth(&self, i: usize) -> usize

Indentation depth of visible row i.

Source

pub fn label(&self, i: usize) -> &str

The label (key or index) of visible row i.

Source

pub fn value(&self, i: usize) -> &str

The value/summary text of visible row i.

Source

pub fn is_container(&self, i: usize) -> bool

Whether visible row i is a container (object/array).

Source

pub fn is_collapsed(&self, i: usize) -> bool

Whether visible row i is a collapsed container.

Source

pub fn to_text(&self) -> String

Serialize the tree back to text in its format.

Source

pub fn mark_saved(&mut self)

Mark the tree as saved (called by the host after a successful write).

Source

pub fn ensure_visible(&mut self, height: usize)

Adjust the scroll so the selected row stays within a height-row window.

Source

pub fn handle_key(&mut self, key: KeyEvent, page: usize) -> Outcome

Interpret a key event and report what the host should do next.

Auto Trait Implementations§

§

impl Freeze for Tree

§

impl RefUnwindSafe for Tree

§

impl Send for Tree

§

impl Sync for Tree

§

impl Unpin for Tree

§

impl UnsafeUnpin for Tree

§

impl UnwindSafe for Tree

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.