Skip to main content

Reading

Struct Reading 

Source
pub struct Reading {
    pub document: Document,
    pub diagnostics: Vec<Diagnostic>,
    pub identities: Vec<Identity>,
    pub parameters: Vec<Parameter>,
    pub footnotes: BTreeMap<String, u32>,
    pub comments: BTreeSet<u32>,
    pub lines: Vec<String>,
    pub front_range: Option<Range>,
    pub back_range: Option<Range>,
    pub policy: Option<Policy>,
    /* private fields */
}
Expand description

A document read: its tree and what the reader learned on the way.

Fields§

§document: Document§diagnostics: Vec<Diagnostic>

The reader’s diagnostics, in source order.

§identities: Vec<Identity>

The explicit identities (§5.3) in source order: directive and keyword ids, heading {#id}s.

§parameters: Vec<Parameter>

The declared parameters (§12), from the front matter and param leaves, in declaration order.

§footnotes: BTreeMap<String, u32>

The footnote labels defined in the document, and the line of their definition.

§comments: BTreeSet<u32>

The lines that held nothing but a comment (§3.3), which leave the body.

§lines: Vec<String>

The source’s lines (a leading BOM removed).

§front_range: Option<Range>

The front matter’s lines: from the opening --- (line 1) to the closing one, both included.

§back_range: Option<Range>

The backmatter’s lines (§3.2): from its --- separator line — a line of exactly --- after a blank line, at the top level, followed by a known backmatter key — to the source’s last line. The separator is part of the range, so the body ends on the line before back_range.start (split_backmatter cuts the text there).

§policy: Option<Policy>

The effective integrations policy (S34): the front matter’s host-integrations (or ReadOptions::host) and integrations merged; None when the document has neither, and for a fragment.

Implementations§

Source§

impl Reading

Source

pub fn source(&self) -> &str

The source as it was given to read (a leading BOM included).

Source

pub fn line_offset(&self, line: u32) -> usize

The byte offset in Reading::source at which a line (1-based) begins; the source’s length past its last.

Source

pub fn changes_text(&self) -> bool

Does the agent text differ from the source? False when the text profile copies the document as written — prose, and rules already in their canonical form (MUST: …), with no metadata, comment, block, typed reference or parameter it rewrites — so a host may hand the source on unchanged; the agent text ends in one newline, which alone is not a change, but a leading BOM or CRLF line endings are (the agent text has neither). Diagnostics are not considered: check them as well (crate::check_reading).

use instruction_md::{read, ReadOptions};

let o = ReadOptions::default();
assert!(!read("Plan the day.\n\nMUST: keep it short.", &o).changes_text());
assert!(read("**MUST:** keep it short.\n", &o).changes_text()); // the text is `MUST: keep it short.`
assert!(read("Plan the day. <!-- for Alex -->\n", &o).changes_text());
Source

pub fn identity(&self, id: &str) -> Option<&Identity>

The explicit identity, if the document has it.

Source

pub fn parameter(&self, name: &str) -> Option<&Parameter>

The declared parameter, if the document declares it.

Source

pub fn has_errors(&self) -> bool

Does the reading have errors?

Source§

impl Reading

Source

pub fn text(&self, params: Option<&Object>) -> String

The text profile of the document read — the agent text — with its own declarations, prose and identities; params are supplied parameter values.

Trait Implementations§

Source§

impl Clone for Reading

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 Reading

Source§

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

Formats the value using the given formatter. Read more

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, 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.