Struct Document

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

Unique identifier for the document

§title: String

Title of the document

§blocks: Vec<Block>

List of blocks in the document

§metadata: HashMap<String, String>

Document metadata

§created_at: u64

Creation timestamp

§updated_at: u64

Last modification timestamp

Implementations§

Source§

impl Document

Source

pub fn new() -> Self

Creates a new empty document

§Example
use blocks::Document;

let doc = Document::new();
assert!(doc.blocks.is_empty());
Source

pub fn with_title(title: String) -> Self

Creates a new document with a title

§Arguments
  • title - The title of the document
§Example
use blocks::Document;

let doc = Document::with_title("My Document".to_string());
assert_eq!(doc.title, "My Document");
Source

pub fn add_block(&mut self, block: Block)

Adds a block to the document

§Arguments
  • block - The block to add
§Example
use blocks::{Document, Block, BlockType};

let mut doc = Document::new();
let block = Block::new(BlockType::Text, "Hello".to_string());
doc.add_block(block);
assert_eq!(doc.blocks.len(), 1);
Source

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

Inserts a block at a specific position

§Arguments
  • index - The position to insert at
  • block - The block to insert
§Returns

Result<(), BlocksError> - Ok if successful, Err if index is out of bounds

Source

pub fn remove_block(&mut self, id: Uuid) -> Result<Block>

Removes a block by its ID

§Arguments
  • id - The ID of the block to remove
§Returns

Result<Block, BlocksError> - The removed block if found

Source

pub fn remove_block_at(&mut self, index: usize) -> Result<Block>

Removes a block by index

§Arguments
  • index - The index of the block to remove
§Returns

Result<Block, BlocksError> - The removed block if found

Source

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

Gets a block by its ID

§Arguments
  • id - The ID of the block to find
§Returns

Option<&Block> - The block if found

Source

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

Gets a mutable reference to a block by its ID

§Arguments
  • id - The ID of the block to find
§Returns

Option<&mut Block> - The mutable block if found

Source

pub fn get_block_at(&self, index: usize) -> Option<&Block>

Gets a block by index

§Arguments
  • index - The index of the block
§Returns

Option<&Block> - The block if found

Source

pub fn get_block_at_mut(&mut self, index: usize) -> Option<&mut Block>

Gets a mutable reference to a block by index

§Arguments
  • index - The index of the block
§Returns

Option<&mut Block> - The mutable block if found

Source

pub fn len(&self) -> usize

Returns the number of blocks in the document

Source

pub fn is_empty(&self) -> bool

Returns true if the document has no blocks

Source

pub fn validate(&self) -> Result<()>

Validates all blocks in the document

Source

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"));
Source

pub fn add_metadata(&mut self, key: String, value: String)

Adds metadata to the document

Source

pub fn get_metadata(&self, key: &str) -> Option<&String>

Gets metadata from the document

Source

pub fn set_title(&mut self, title: String)

Updates the document title

Source

pub fn clear(&mut self)

Clears all blocks from the document

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 Convertible for Document

Source§

fn to_format(&self, format: ConversionFormat) -> Result<String>

Converts the object to the specified format Read more
Source§

impl Debug for Document

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Document

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Document

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Document

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Document

Source§

fn eq(&self, other: &Document) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Document

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Document

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,