Skip to main content

Document

Struct Document 

Source
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: DocumentId

Document identifier

§root: BlockId

Root block ID

§structure: HashMap<BlockId, Vec<BlockId>>

Adjacency map: parent -> ordered children

§blocks: HashMap<BlockId, Block>

All blocks in the document

§metadata: DocumentMetadata

Document-level metadata

§indices: DocumentIndices

Secondary indices for fast lookup

§edge_index: EdgeIndex

Edge index for relationship traversal

§version: DocumentVersion

Document version for concurrency control

Implementations§

Source§

impl Document

Source

pub fn new(id: DocumentId) -> Self

Create a new empty document

Source

pub fn create() -> Self

Create with a generated ID

Source

pub fn with_metadata(self, metadata: DocumentMetadata) -> Self

Set document metadata

Source

pub fn get_block(&self, id: &BlockId) -> Option<&Block>

Get a block by ID

Source

pub fn get_block_mut(&mut self, id: &BlockId) -> Option<&mut Block>

Get a mutable block by ID

Source

pub fn children(&self, parent: &BlockId) -> &[BlockId]

Get children of a block

Source

pub fn parent(&self, child: &BlockId) -> Option<&BlockId>

Get parent of a block

Source

pub fn parent_of(&self, child: &BlockId) -> Option<&Block>

Get the parent block (convenience method)

Source

pub fn add_block(&mut self, block: Block, parent: &BlockId) -> Result<BlockId>

Add a block to the document

Source

pub fn add_block_at( &mut self, block: Block, parent: &BlockId, index: usize, ) -> Result<BlockId>

Add a block at a specific position

Source

pub fn add_edge( &mut self, source: &BlockId, edge_type: EdgeType, target: BlockId, )

Add an edge between two blocks (wrapper for edge_index)

Source

pub fn remove_from_structure(&mut self, id: &BlockId) -> bool

Remove a block from the structure (makes it orphaned)

Source

pub fn delete_block(&mut self, id: &BlockId) -> Result<Block>

Delete a block completely

Source

pub fn delete_cascade(&mut self, id: &BlockId) -> Result<Vec<Block>>

Delete a block and all its descendants

Source

pub fn move_block(&mut self, id: &BlockId, new_parent: &BlockId) -> Result<()>

Move a block to a new parent

Source

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

Source

pub fn move_block_before( &mut self, id: &BlockId, before: &BlockId, ) -> Result<()>

Move a block before another block (sibling ordering)

Source

pub fn move_block_after(&mut self, id: &BlockId, after: &BlockId) -> Result<()>

Move a block after another block (sibling ordering)

Source

pub fn is_ancestor(&self, potential_ancestor: &BlockId, block: &BlockId) -> bool

Check if a block is an ancestor of another

Source

pub fn descendants(&self, id: &BlockId) -> Vec<BlockId>

Get all descendants of a block

Source

pub fn is_reachable(&self, id: &BlockId) -> bool

Check if a block is reachable from root

Source

pub fn find_orphans(&self) -> Vec<BlockId>

Find all orphaned blocks

Source

pub fn block_state(&self, id: &BlockId) -> BlockState

Get block state

Source

pub fn prune_unreachable(&mut self) -> Vec<Block>

Prune unreachable blocks

Source

pub fn block_count(&self) -> usize

Get total block count

Source

pub fn total_tokens(&self, model: TokenModel) -> u32

Get total token estimate

Source

pub fn validate(&self) -> Vec<ValidationIssue>

Validate document structure

Source

pub fn rebuild_indices(&mut self)

Rebuild all indices

Trait Implementations§

Source§

impl Clone for Document

Source§

fn clone(&self) -> Document

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Document

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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

Source§

type Output = T

Should always be Self
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.