Skip to main content

Reader

Struct Reader 

Source
pub(super) struct Reader<'a> {
    text: &'a str,
    document: &'a YamlDoc,
    step: usize,
}
Expand description

Reads a document by the byte spans yaml-rt reports.

A mapping that does not fit the tree, such as one with explicit or complex keys, is kept as raw text instead.

Fields§

§text: &'a str§document: &'a YamlDoc§step: usize

Implementations§

Source§

impl Reader<'_>

Source

pub(super) fn opaque( &self, site: Site, node: NodeId, span: Bounds, ) -> Result<Parsed<Value>, DocumentError>

A mapping the tree cannot edit, kept as raw text. A flow mapping with entries also gets the block rewrite that edits use.

Source

pub(super) fn is_flow_with_entries(&self, node: NodeId) -> bool

Whether node is a flow mapping with entries.

Source

fn flow_rewrite( &self, site: Site, node: NodeId, span: Bounds, end: usize, ) -> Result<Option<Mapping>, DocumentError>

The flow mapping node as a block mapping, or None when it has a comment, a key that is not a scalar, or a value that spans lines. end is where the line of the closing brace ends.

Source

fn push_line(out: &mut String, pad: &str, key: &str, rest: &str)

Source

fn block_source( &self, node: NodeId, indent: usize, ) -> Result<Option<String>, DocumentError>

The entries of the flow mapping node written as block source with keys at indent. A document cannot start indented, so the caller moves the result to where the mapping sits.

Source§

impl Reader<'_>

Source

pub(super) fn value( &self, name: &str, node: NodeId, span: Bounds, colon_end: usize, indent: usize, ) -> Result<Parsed<Value>, DocumentError>

The value of a key as a node, and where its text ends. A mapping the tree cannot edit is kept as raw text.

Source

pub(super) fn mapping_style(&self, node: NodeId) -> Option<CollectionStyle>

The style of node when it is a mapping.

Source

pub(super) fn mapping( &self, node: NodeId, span: Bounds, site: Site, ) -> Result<Option<Parsed<Mapping>>, DocumentError>

node as an editable mapping, or None when it is not a mapping, is a flow mapping with entries, or does not fit the tree.

Source

fn block_mapping( &self, node: NodeId, site: Site, ) -> Result<Option<Parsed<Mapping>>, DocumentError>

Source

fn empty_flow_mapping( &self, node: NodeId, span: Bounds, site: Site, ) -> Result<Option<Parsed<Mapping>>, DocumentError>

Source§

impl<'a> Reader<'a>

Source

pub(super) fn new(text: &'a str, document: &'a YamlDoc) -> Self

Source

pub(super) fn tree(&self) -> Result<Tree, DocumentError>

Source

fn block( &self, mapping: NodeId, from: usize, ) -> Result<Option<Parsed<Block>>, DocumentError>

The entries of a block mapping, with the first one’s leading text starting at from. A mapping that does not fit the tree stays raw. A key that appears twice is an error.

Source

fn entry( &self, key: NodeId, value: NodeId, cursor: usize, ) -> Result<Option<Parsed<Entry>>, DocumentError>

Source

fn leaf( &self, colon_end: usize, value: NodeId, span: Bounds, ) -> Result<Parsed<Leaf>, DocumentError>

A value kept as raw text. What follows it on its last line, such as a comment, goes into the tail.

Source

fn scalar(&self, node: NodeId) -> Option<String>

The value of a scalar node, with quotes removed and escapes resolved.

Source

fn comment_start(&self, value: NodeId, span: Bounds, fallback: usize) -> usize

Where the whitespace before a trailing comment starts, or fallback when there is no comment inside the value’s span.

yaml-rt extends the span of a plain scalar over a comment that follows it. Other scalars end before it.

Source

fn empty_braces(&self, node: NodeId, span: Bounds) -> Option<usize>

The offset of the { of a flow mapping with nothing but whitespace between its braces, which ends its node.

Source

fn colon_end(&self, key_end: usize) -> Option<usize>

The offset after the colon that follows a key.

Source

fn extent(&self, node: NodeId) -> Result<Bounds, DocumentError>

The span of a node, widened to cover its descendants.

yaml-rt ends a collection’s span before the content of a block scalar that closes it.

Source

fn range(&self, node: NodeId) -> Result<Bounds, DocumentError>

Source

fn slice(&self, start: usize, end: usize) -> Result<&'a str, DocumentError>

Source

fn line_start(&self, offset: usize) -> usize

The offset of the start of the line that holds offset.

Source

fn line_end(&self, offset: usize) -> usize

The offset after the line break that ends the line holding offset. An offset that already follows a line break is its own answer.

Source

fn with_detected_step(self) -> Self

Source

fn detect_step(&self, mapping: NodeId) -> Option<usize>

The indent of the first nested block mapping below its key.

Auto Trait Implementations§

§

impl<'a> Freeze for Reader<'a>

§

impl<'a> RefUnwindSafe for Reader<'a>

§

impl<'a> Send for Reader<'a>

§

impl<'a> Sync for Reader<'a>

§

impl<'a> Unpin for Reader<'a>

§

impl<'a> UnsafeUnpin for Reader<'a>

§

impl<'a> UnwindSafe for Reader<'a>

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> 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, 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, <T as TryFrom<U>>::Error>

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.