pub struct Document {
pub doc_id: String,
pub doc_name: String,
pub source_type: SourceType,
pub doc_description: String,
pub source_path: String,
pub structure: Vec<Node>,
}Expand description
A parsed document with its tree structure.
Fields§
§doc_id: String§doc_name: String§source_type: SourceType§doc_description: String§source_path: String§structure: Vec<Node>Implementations§
Source§impl Document
impl Document
Sourcepub fn new(
doc_id: impl Into<String>,
doc_name: impl Into<String>,
source_type: SourceType,
) -> Self
pub fn new( doc_id: impl Into<String>, doc_name: impl Into<String>, source_type: SourceType, ) -> Self
Creates an empty document with stable transport metadata.
Sourcepub fn flatten_nodes(&self) -> Vec<&Node>
pub fn flatten_nodes(&self) -> Vec<&Node>
Flatten all nodes in the document tree.
Sourcepub fn build_node_map(&self) -> HashMap<&str, &Node>
pub fn build_node_map(&self) -> HashMap<&str, &Node>
Builds a borrowed node lookup table for repeated search operations.
Call Document::validate_structure first when identities come from an
untrusted host; duplicate IDs would otherwise keep the last node.
Sourcepub fn validate_structure(&self) -> Result<(), DocumentStructureError>
pub fn validate_structure(&self) -> Result<(), DocumentStructureError>
Validates identities and source ranges required by search maps.
Sourcepub fn build_parent_map(&self) -> HashMap<String, Option<String>>
pub fn build_parent_map(&self) -> HashMap<String, Option<String>>
Build parent map: node_id -> parent_node_id (None for roots).
Sourcepub fn build_depth_map(&self) -> HashMap<String, u32>
pub fn build_depth_map(&self) -> HashMap<String, u32>
Build depth map: node_id -> depth (0 for roots).
Sourcepub fn max_depth(&self) -> u32
pub fn max_depth(&self) -> u32
Returns the maximum one-based tree depth, or zero for an empty document.
Sourcepub fn build_children_map(&self) -> HashMap<String, Vec<String>>
pub fn build_children_map(&self) -> HashMap<String, Vec<String>>
Build children map: node_id -> list of child node_ids.
Sourcepub fn path_to_node(&self, node_id: &str) -> Vec<String>
pub fn path_to_node(&self, node_id: &str) -> Vec<String>
Get path from root to a node (list of node_ids, root first).
Sourcepub fn assign_node_ids(&mut self)
pub fn assign_node_ids(&mut self)
Assign sequential node IDs to all nodes.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Document
impl<'de> Deserialize<'de> for Document
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnsafeUnpin for Document
impl UnwindSafe for Document
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more