pub struct Document {
pub id: Uuid,
pub title: String,
pub blocks: Vec<Block>,
pub metadata: HashMap<String, String>,
pub created_at: u64,
pub updated_at: u64,
}Expand description
Represents a document containing multiple blocks
Fields§
§id: UuidUnique identifier for the document
title: StringTitle of the document
blocks: Vec<Block>List of blocks in the document
metadata: HashMap<String, String>Document metadata
created_at: u64Creation timestamp
updated_at: u64Last modification timestamp
Implementations§
Source§impl Document
impl Document
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty document
§Example
use blocks::Document;
let doc = Document::new();
assert!(doc.blocks.is_empty());Sourcepub fn with_title(title: String) -> Self
pub fn with_title(title: String) -> Self
Sourcepub fn remove_block(&mut self, id: Uuid) -> Result<Block>
pub fn remove_block(&mut self, id: Uuid) -> Result<Block>
Sourcepub fn remove_block_at(&mut self, index: usize) -> Result<Block>
pub fn remove_block_at(&mut self, index: usize) -> Result<Block>
Sourcepub fn get_block_mut(&mut self, id: Uuid) -> Option<&mut Block>
pub fn get_block_mut(&mut self, id: Uuid) -> Option<&mut Block>
Sourcepub fn get_block_at(&self, index: usize) -> Option<&Block>
pub fn get_block_at(&self, index: usize) -> Option<&Block>
Sourcepub fn get_block_at_mut(&mut self, index: usize) -> Option<&mut Block>
pub fn get_block_at_mut(&mut self, index: usize) -> Option<&mut Block>
Sourcepub fn to_format(&self, format: ConversionFormat) -> Result<String>
pub fn to_format(&self, format: ConversionFormat) -> Result<String>
Converts the document to a specific format
§Arguments
format- The format to convert to
§Returns
Result<String, BlocksError> - The converted document
§Example
use blocks::{Document, Block, BlockType, ConversionFormat};
let mut doc = Document::new();
doc.add_block(Block::new(BlockType::Text, "Hello".to_string()));
let markdown = doc.to_format(ConversionFormat::Markdown).unwrap();
assert!(markdown.contains("Hello"));Sourcepub fn add_metadata(&mut self, key: String, value: String)
pub fn add_metadata(&mut self, key: String, value: String)
Adds metadata to the document
Sourcepub fn get_metadata(&self, key: &str) -> Option<&String>
pub fn get_metadata(&self, key: &str) -> Option<&String>
Gets metadata from the document
Trait Implementations§
Source§impl Convertible for Document
impl Convertible for Document
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
impl StructuralPartialEq for Document
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin 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