pub struct Document {
pub source: String,
pub path: Option<PathBuf>,
pub title: Option<String>,
}Expand description
A Scrybe document — Markdown source with associated metadata.
Holds raw source text and a lazily-computed content identifier.
Rendering happens in scrybe-render (P1.3).
Fields§
§source: StringThe Markdown source text.
path: Option<PathBuf>Optional on-disk path. None for untitled / in-memory documents.
title: Option<String>Document title extracted from the first H1, if present.
Implementations§
Source§impl Document
impl Document
Sourcepub fn new(source: impl Into<String>) -> Self
pub fn new(source: impl Into<String>) -> Self
Creates a new in-memory document with the given source.
Sourcepub fn from_file(path: PathBuf, source: impl Into<String>) -> Self
pub fn from_file(path: PathBuf, source: impl Into<String>) -> Self
Creates a document from a file path and its source.
The title is populated automatically from the first H1 heading.
Sourcepub fn title_from_ast(&self) -> Option<String>
pub fn title_from_ast(&self) -> Option<String>
Returns the title extracted from the first H1 in the source, if any.
Sourcepub fn to_cbor(&self) -> Result<Vec<u8>, ScrybeError>
pub fn to_cbor(&self) -> Result<Vec<u8>, ScrybeError>
Serialises this document to deterministic CBOR bytes.
Sourcepub fn from_cbor(bytes: &[u8]) -> Result<Self, ScrybeError>
pub fn from_cbor(bytes: &[u8]) -> Result<Self, ScrybeError>
Deserialises a document from CBOR bytes.
Trait Implementations§
Source§impl ContentAddressable for Document
impl ContentAddressable for Document
Source§fn content_id(&self) -> ContentId
fn content_id(&self) -> ContentId
Returns the content identifier for this value.
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
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnsafeUnpin 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