pub struct Document {
pub id: DocumentId,
pub root: BlockId,
pub structure: HashMap<BlockId, Vec<BlockId>>,
pub blocks: HashMap<BlockId, Block>,
pub metadata: DocumentMetadata,
pub indices: DocumentIndices,
pub edge_index: EdgeIndex,
pub version: DocumentVersion,
}Expand description
A UCM document is a collection of blocks with hierarchical structure.
Fields§
§id: DocumentIdDocument identifier
root: BlockIdRoot block ID
structure: HashMap<BlockId, Vec<BlockId>>Adjacency map: parent -> ordered children
blocks: HashMap<BlockId, Block>All blocks in the document
metadata: DocumentMetadataDocument-level metadata
indices: DocumentIndicesSecondary indices for fast lookup
edge_index: EdgeIndexEdge index for relationship traversal
version: DocumentVersionDocument version for concurrency control
Implementations§
Source§impl Document
impl Document
Sourcepub fn new(id: DocumentId) -> Self
pub fn new(id: DocumentId) -> Self
Create a new empty document
Sourcepub fn with_metadata(self, metadata: DocumentMetadata) -> Self
pub fn with_metadata(self, metadata: DocumentMetadata) -> Self
Set document metadata
Sourcepub fn get_block_mut(&mut self, id: &BlockId) -> Option<&mut Block>
pub fn get_block_mut(&mut self, id: &BlockId) -> Option<&mut Block>
Get a mutable block by ID
Sourcepub fn parent_of(&self, child: &BlockId) -> Option<&Block>
pub fn parent_of(&self, child: &BlockId) -> Option<&Block>
Get the parent block (convenience method)
Sourcepub fn add_block(&mut self, block: Block, parent: &BlockId) -> Result<BlockId>
pub fn add_block(&mut self, block: Block, parent: &BlockId) -> Result<BlockId>
Add a block to the document
Sourcepub fn add_block_at(
&mut self,
block: Block,
parent: &BlockId,
index: usize,
) -> Result<BlockId>
pub fn add_block_at( &mut self, block: Block, parent: &BlockId, index: usize, ) -> Result<BlockId>
Add a block at a specific position
Sourcepub fn add_edge(
&mut self,
source: &BlockId,
edge_type: EdgeType,
target: BlockId,
)
pub fn add_edge( &mut self, source: &BlockId, edge_type: EdgeType, target: BlockId, )
Add an edge between two blocks (wrapper for edge_index)
Sourcepub fn remove_from_structure(&mut self, id: &BlockId) -> bool
pub fn remove_from_structure(&mut self, id: &BlockId) -> bool
Remove a block from the structure (makes it orphaned)
Sourcepub fn delete_block(&mut self, id: &BlockId) -> Result<Block>
pub fn delete_block(&mut self, id: &BlockId) -> Result<Block>
Delete a block completely
Sourcepub fn delete_cascade(&mut self, id: &BlockId) -> Result<Vec<Block>>
pub fn delete_cascade(&mut self, id: &BlockId) -> Result<Vec<Block>>
Delete a block and all its descendants
Sourcepub fn move_block(&mut self, id: &BlockId, new_parent: &BlockId) -> Result<()>
pub fn move_block(&mut self, id: &BlockId, new_parent: &BlockId) -> Result<()>
Move a block to a new parent
Sourcepub fn move_block_at(
&mut self,
id: &BlockId,
new_parent: &BlockId,
index: usize,
) -> Result<()>
pub fn move_block_at( &mut self, id: &BlockId, new_parent: &BlockId, index: usize, ) -> Result<()>
Move a block to a specific position under a parent
Sourcepub fn move_block_before(
&mut self,
id: &BlockId,
before: &BlockId,
) -> Result<()>
pub fn move_block_before( &mut self, id: &BlockId, before: &BlockId, ) -> Result<()>
Move a block before another block (sibling ordering)
Sourcepub fn move_block_after(&mut self, id: &BlockId, after: &BlockId) -> Result<()>
pub fn move_block_after(&mut self, id: &BlockId, after: &BlockId) -> Result<()>
Move a block after another block (sibling ordering)
Sourcepub fn is_ancestor(&self, potential_ancestor: &BlockId, block: &BlockId) -> bool
pub fn is_ancestor(&self, potential_ancestor: &BlockId, block: &BlockId) -> bool
Check if a block is an ancestor of another
Sourcepub fn descendants(&self, id: &BlockId) -> Vec<BlockId>
pub fn descendants(&self, id: &BlockId) -> Vec<BlockId>
Get all descendants of a block
Sourcepub fn is_reachable(&self, id: &BlockId) -> bool
pub fn is_reachable(&self, id: &BlockId) -> bool
Check if a block is reachable from root
Sourcepub fn find_orphans(&self) -> Vec<BlockId>
pub fn find_orphans(&self) -> Vec<BlockId>
Find all orphaned blocks
Sourcepub fn block_state(&self, id: &BlockId) -> BlockState
pub fn block_state(&self, id: &BlockId) -> BlockState
Get block state
Sourcepub fn prune_unreachable(&mut self) -> Vec<Block>
pub fn prune_unreachable(&mut self) -> Vec<Block>
Prune unreachable blocks
Sourcepub fn block_count(&self) -> usize
pub fn block_count(&self) -> usize
Get total block count
Sourcepub fn total_tokens(&self, model: TokenModel) -> u32
pub fn total_tokens(&self, model: TokenModel) -> u32
Get total token estimate
Sourcepub fn validate(&self) -> Vec<ValidationIssue>
pub fn validate(&self) -> Vec<ValidationIssue>
Validate document structure
Sourcepub fn rebuild_indices(&mut self)
pub fn rebuild_indices(&mut self)
Rebuild all indices