Skip to main content

Doc

Struct Doc 

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

A guarded handle on a Document tree: an arena of nodes plus the root.

Implementations§

Source§

impl Doc

Source

pub fn of(value: &Value) -> Result<Doc, DocumentError>

Build a Doc from a plain Value.

Source

pub fn root(&self) -> Cursor<'_>

A cursor to the document root, at path "$".

Source

pub fn add( &mut self, at: NodeId, path: &str, label: &str, value: &Value, ) -> Result<NodeId, DocumentError>

Append an edge (label, value) under the node at at/path. A repeated label is how an array grows. Returns the new edge’s NodeId.

Source

pub fn set( &mut self, at: NodeId, path: &str, label: &str, value: &Value, ) -> Result<NodeId, DocumentError>

Replace all edges under label with a single new edge, positioned at the first old occurrence (set = remove + add).

Source

pub fn remove( &mut self, at: NodeId, path: &str, label: &str, ) -> Result<(), DocumentError>

Remove every edge under label.

Source

pub fn to_grouped(&self) -> Value

A JSON-shaped projection of the whole document: same-label edges grouped into an array; a label seen once stays a single value.

Source

pub fn to_data(&self) -> Value

A lossless copy of the whole document back into Value form.

Source

pub fn eq_doc(&self, other: &Doc) -> bool

Structural equality between two documents (same shape, same edge order, same labels, same leaf values).

Source§

impl Doc

Source

pub fn from_raw(root: RawNode) -> Result<Doc, DocumentError>

Build a Doc from a RawNode, preserving edge order and interleaving exactly. Depth-guarded via the same check_write_depth every other construction path uses.

Source

pub fn to_raw(&self) -> RawNode

The inverse of Doc::from_raw: a lossless walk back into RawNode form, preserving edge order and interleaving exactly.

Source§

impl Doc

Name-keyed dispatch through crate::registry (issue #31), mirroring Python’s Doc.from_format/to_format/check_format in ~/dev/omnist/omnist/document.py. Kept as its own impl Doc block (rather than folded into the constructors/export blocks above) since it is the one place Doc depends on the registry module rather than a single format module directly.

Source

pub fn from_format(name: &str, text: &str) -> Result<Doc, OmnistError>

Read text as the registered format name (an crate::error::OmnistError::Format if name isn’t registered). Mirrors Python’s Doc.from_format(name, text).

Source

pub fn to_format(&self, name: &str) -> Result<String, OmnistError>

Write self as the registered format name. Mirrors Python’s Doc.to_format(name).

Source

pub fn check_format(&self, name: &str) -> Result<WriteReport, OmnistError>

Simulate writing self as the registered format name, without producing output. Mirrors Python’s Doc.check_format(name): an crate::error::OmnistError::Document if name’s registered crate::registry::Format has no check callable (a plugin registered via crate::registry::Format::new alone) – not a panic.

Trait Implementations§

Source§

impl Clone for Doc

Source§

fn clone(&self) -> Doc

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 Debug for Doc

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Doc

§

impl RefUnwindSafe for Doc

§

impl Send for Doc

§

impl Sync for Doc

§

impl Unpin for Doc

§

impl UnsafeUnpin for Doc

§

impl UnwindSafe for Doc

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, 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.