Skip to main content

Node

Struct Node 

Source
pub struct Node {
    pub node_type: NodeType,
    pub kind: String,
    pub form: Option<Form>,
    pub attrs: Attrs,
    pub children: Option<Vec<Node>>,
    pub value: Option<StructuredValue>,
    pub source: String,
    pub range: Option<Range>,
    pub instance: String,
    /* private fields */
}
Expand description

A node of the tree: a Markdown segment (its source) or a directive.

Fields§

§node_type: NodeType§kind: String

A directive’s kind (must, policy, charts:metric); empty for Markdown.

§form: Option<Form>

A directive’s form; None for Markdown.

§attrs: Attrs§children: Option<Vec<Node>>

A Markdown-bodied directive’s parsed body; a literal body (an example’s, a verbatim one) is one Markdown node. None: the directive has no such body (a leaf, a structured body); empty: an empty one.

§value: Option<StructuredValue>

A structured or literal-format body (YAML, JSON, CSV, text, HTML, code).

§source: String

A Markdown node’s text, or the full source of a directive this reader does not interpret.

§range: Option<Range>§instance: String

A resolved node’s composition path (§2, §14.1): root, root/personal.

Implementations§

Source§

impl Node

Source

pub fn markdown(source: impl Into<String>) -> Node

A Markdown node.

Source

pub fn directive(kind: impl Into<String>, form: Form, attrs: Attrs) -> Node

A directive node.

Source

pub fn is_markdown(&self) -> bool

Source

pub fn is_directive(&self) -> bool

Source

pub fn keyword(&self) -> Option<&str>

The keyword a keyword rule or an alert was written with (ALWAYS, AVOID, MUST NOT); the tree keeps its normalized kind. Set by the reader.

Source

pub fn reason_range(&self) -> Option<Range>

The lines of a rule’s BECAUSE: reason, which the tree keeps as the rule’s because. Set by the reader.

Source

pub fn is_prose(&self) -> bool

Is this Markdown node parsed prose (not an example’s or a verbatim body’s quoted text)? Set by the reader.

Source

pub fn body_source(&self) -> Option<&str>

The exact source text of a container’s body, as the reader read it: every line between the opening fence’s line and the closing fence’s (each with its line ending, comments and all; empty for an empty body), or to the end of the source when the container is not closed. None for any other node, and for a node not read from source (built, or decoded from a tree’s JSON).

use instruction_md::{read, ReadOptions};

let r = read(":::skill{id=plan}\nPlan the day.\n<!-- kept -->\n:::\n", &ReadOptions::default());
assert_eq!(r.document.body[0].body_source(), Some("Plan the day.\n<!-- kept -->\n"));
Source

pub fn children(&self) -> &[Node]

The node’s children, or none.

Source

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

A string attribute.

Source

pub fn to_json(&self) -> Value

The node as instruction.schema.json has it.

Source

pub fn from_json(v: &Value) -> Result<Node, String>

Reads a node of a tree.

Trait Implementations§

Source§

impl Clone for Node

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 Node

Source§

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

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

impl PartialEq for Node

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 Node

Auto Trait Implementations§

§

impl Forget for Node

§

impl Freeze for Node

§

impl Move for Node

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnsafeUnpin for Node

§

impl UnwindSafe for Node

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.