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
impl Reading
Sourcepub fn line_offset(&self, line: u32) -> usize
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.
Sourcepub fn changes_text(&self) -> bool
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());Sourcepub fn identity(&self, id: &str) -> Option<&Identity>
pub fn identity(&self, id: &str) -> Option<&Identity>
The explicit identity, if the document has it.
Sourcepub fn parameter(&self, name: &str) -> Option<&Parameter>
pub fn parameter(&self, name: &str) -> Option<&Parameter>
The declared parameter, if the document declares it.
Sourcepub fn has_errors(&self) -> bool
pub fn has_errors(&self) -> bool
Does the reading have errors?