pub struct Block {
pub id: BlockId,
pub content: Content,
pub metadata: BlockMetadata,
pub edges: Vec<Edge>,
pub version: Version,
}Expand description
A block is the fundamental unit of content in UCM.
Blocks are immutable, content-addressed units identified by deterministic IDs derived from their content. They contain typed content, metadata for search and display, and edges representing relationships to other blocks.
§Example
use ucm_core::{Block, Content};
let block = Block::new(Content::text("Hello, UCM!"), Some("intro"));
println!("Block ID: {}", block.id);Fields§
§id: BlockIdUnique, content-derived identifier
content: ContentThe actual content
metadata: BlockMetadataBlock metadata
edges: Vec<Edge>Explicit relationships to other blocks
version: VersionVersion for optimistic concurrency control
Implementations§
Source§impl Block
impl Block
Sourcepub fn new(content: Content, semantic_role: Option<&str>) -> Self
pub fn new(content: Content, semantic_role: Option<&str>) -> Self
Create a new block with generated ID
Sourcepub fn with_id(id: BlockId, content: Content) -> Self
pub fn with_id(id: BlockId, content: Content) -> Self
Create a new block with a specific ID (for deserialization or testing)
Sourcepub fn with_metadata(self, metadata: BlockMetadata) -> Self
pub fn with_metadata(self, metadata: BlockMetadata) -> Self
Set metadata
Sourcepub fn with_label(self, label: impl Into<String>) -> Self
pub fn with_label(self, label: impl Into<String>) -> Self
Set label
Sourcepub fn with_edges(self, edges: impl IntoIterator<Item = Edge>) -> Self
pub fn with_edges(self, edges: impl IntoIterator<Item = Edge>) -> Self
Add multiple edges
Sourcepub fn content_type(&self) -> &'static str
pub fn content_type(&self) -> &'static str
Get the content type tag
Sourcepub fn token_estimate(&self) -> TokenEstimate
pub fn token_estimate(&self) -> TokenEstimate
Get the estimated token count
Sourcepub fn size_bytes(&self) -> usize
pub fn size_bytes(&self) -> usize
Get content size in bytes
Sourcepub fn update_content(&mut self, content: Content, semantic_role: Option<&str>)
pub fn update_content(&mut self, content: Content, semantic_role: Option<&str>)
Update the content and regenerate ID
Sourcepub fn remove_edge(&mut self, target: &BlockId, edge_type: &EdgeType) -> bool
pub fn remove_edge(&mut self, target: &BlockId, edge_type: &EdgeType) -> bool
Remove an edge by target and type
Sourcepub fn edges_of_type(&self, edge_type: &EdgeType) -> Vec<&Edge>
pub fn edges_of_type(&self, edge_type: &EdgeType) -> Vec<&Edge>
Get edges of a specific type
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Block
impl<'de> Deserialize<'de> for Block
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
impl StructuralPartialEq for Block
Auto Trait Implementations§
impl Freeze for Block
impl RefUnwindSafe for Block
impl Send for Block
impl Sync for Block
impl Unpin for Block
impl UnwindSafe for Block
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