Skip to main content

NoteDocument

Struct NoteDocument 

Source
pub struct NoteDocument { /* private fields */ }
Expand description

A parsed nb note, todo, or bookmark.

NoteDocument owns the complete original source as Vec<u8>. The source is byte-identical to the input passed to [parse]. The kind-specific ownership partition is exposed via accessor methods (e.g., NoteDocument::title, NoteDocument::body, NoteDocument::url) and the NoteDocument::tag_token_spans view.

See the P1 specification for the full contract.

Implementations§

Source§

impl NoteDocument

Source

pub fn source(&self) -> &[u8] ⓘ

The original source bytes, byte-identical to the input passed to [parse].

Source

pub fn emit(&self) -> &[u8] ⓘ

Returns a slice into the retained source bytes, byte-identical to the original input. Equivalent to NoteDocument::source.

Source

pub fn verify_partition(&self) -> Result<(), &'static str>

Verify the ownership partition satisfies the P1 invariants: union covers [0, source.len()) exactly, ranges are pairwise disjoint, each range is half-open and within bounds. Returns Ok(()) on success or an Err(&'static str) describing the first violation.

Used by integration tests and by parse itself when the debug_assertions cfg flag is enabled. Production callers do not need to invoke this; it exists to surface parser regressions during testing.

Source

pub fn kind(&self) -> DocumentKind

The DocumentKind of this document.

Source

pub fn todo_state(&self) -> Option<TodoState>

For Todo documents, the parsed checkbox state. None for non-Todo documents and for Todo documents whose title has no [ ]/[x] prefix (permissive acceptance).

Source

pub fn title(&self) -> Option<&[u8]>

The raw title line bytes (including trailing newline); None if no valid ATX H1 title.

Source

pub fn title_str(&self) -> Option<Result<&str, Utf8Error>>

Option<Result<&str, std::str::Utf8Error>> view of the title. None for no title; Some(Ok(_)) for valid UTF-8; Some(Err(_)) for invalid UTF-8.

Source

pub fn tags_prefix(&self) -> Option<&[u8]>

For Note documents, the raw tags prefix line bytes (including trailing newline); None otherwise.

Source

pub fn tag_section(&self) -> Option<&[u8]>

For Todo/Bookmark documents, the raw tags-section bytes (the entire H2 Tags section including its trailing newline); None otherwise.

Source

pub fn tags(&self) -> TagsIter<'_> ⓘ

Iterator over tag token byte spans (&[u8]). Tokens come from tags_prefix_range for Note documents and from tag_section_range for Todo/Bookmark documents. Spans reference bytes owned by the source.

Source

pub fn tags_str(&self) -> TagsStrIter<'_> ⓘ

Iterator yielding Result<&str, std::str::Utf8Error> per tag token.

Source

pub fn tag_token_spans(&self) -> Vec<Range<usize>>

All tag token spans across the document. For Note, tokens come from tags_prefix_range; for Todo/Bookmark, from tag_section_range. Spans reference bytes owned by the source and SHALL NOT themselves own bytes.

Source

pub fn body_ranges(&self) -> Vec<Range<usize>>

Body partition ranges in source order (half-open byte offsets).

Source

pub fn body(&self) -> BodyFragments<'_> ⓘ

Iterator over body byte ranges (in source order).

Source

pub fn body_bytes(&self) -> Vec<u8> ⓘ

Concatenated body fragment bytes in source order (fingerprint domain).

Source

pub fn title_byte_range(&self) -> Option<Range<usize>>

Title line byte range when present (includes trailing newline).

Source

pub fn tags_byte_range(&self) -> Option<Range<usize>>

Tags-prefix (Note) or tags-section (Todo/Bookmark) byte range.

Source

pub fn url(&self) -> Option<&[u8]>

For Bookmark documents, the raw URL line bytes (including trailing newline); None for non-Bookmark documents or Bookmarks without a <URL> line.

Source

pub fn url_str(&self) -> Option<Result<&str, Utf8Error>>

Option<Result<&str, std::str::Utf8Error>> view of the URL.

Trait Implementations§

Source§

impl Clone for NoteDocument

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for NoteDocument

Source§

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

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

impl Eq for NoteDocument

Source§

impl PartialEq for NoteDocument

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for NoteDocument

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more