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
impl Doc
Sourcepub fn add(
&mut self,
at: NodeId,
path: &str,
label: &str,
value: &Value,
) -> Result<NodeId, DocumentError>
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.
Sourcepub fn set(
&mut self,
at: NodeId,
path: &str,
label: &str,
value: &Value,
) -> Result<NodeId, DocumentError>
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).
Sourcepub fn remove(
&mut self,
at: NodeId,
path: &str,
label: &str,
) -> Result<(), DocumentError>
pub fn remove( &mut self, at: NodeId, path: &str, label: &str, ) -> Result<(), DocumentError>
Remove every edge under label.
Sourcepub fn to_grouped(&self) -> Value
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§impl Doc
impl Doc
Sourcepub fn from_raw(root: RawNode) -> Result<Doc, DocumentError>
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.
Sourcepub fn to_raw(&self) -> RawNode
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.
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.
Sourcepub fn from_format(name: &str, text: &str) -> Result<Doc, OmnistError>
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).
Sourcepub fn to_format(&self, name: &str) -> Result<String, OmnistError>
pub fn to_format(&self, name: &str) -> Result<String, OmnistError>
Write self as the registered format name. Mirrors Python’s
Doc.to_format(name).
Sourcepub fn check_format(&self, name: &str) -> Result<WriteReport, OmnistError>
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.