Struct Document

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

Represents a queryable YAML document.

Implementations§

Source§

impl Document

Source

pub fn new(source: impl Into<String>) -> Result<Self, QueryError>

Construct a new Document from the given YAML.

Source

pub fn source(&self) -> &str

Return a view of the original YAML source that this document was loaded from.

Source

pub fn root(&self) -> Feature<'_>

Returns a Feature for this document’s root node.

This is typically useful as a “fallback” feature, e.g. for capturing a span of the entire document.

Source

pub fn range_spanned_by_comment(&self, start: usize, end: usize) -> bool

Returns whether the given range is spanned by a comment node.

The comment node must fully span the range; a range that ends after the comment or starts before it will not be considered spanned.

Source

pub fn offset_inside_comment(&self, offset: usize) -> bool

Returns whether the given offset is within a comment node’s span.

Source

pub fn query(&self, query: &Query) -> Result<Feature<'_>, QueryError>

Perform a query on the current document, returning a Feature if the query succeeds.

Source

pub fn extract(&self, feature: &Feature<'_>) -> &str

Returns a string slice of the original document corresponding to the given Feature.

This function returns a slice corresponding to the Feature’s exact span, meaning that leading whitespace for the start point is not necessarily captured. See Self::extract_with_leading_whitespace for feature extraction with rudimentary whitespace handling.

Panics if the feature’s span is invalid.

Source

pub fn extract_with_leading_whitespace(&self, feature: &Feature<'_>) -> &str

Returns a string slice of the original document corresponding to the given Feature, along with any leading (indentation-semantic) whitespace.

Important: The returned string here can be longer than the span identified in the Feature. In particular, this API will return a longer string if it identifies leading non-newline whitespace ahead of the captured Feature, since this indicates indentation not encapsulated by the feature itself.

Panics if the feature’s span is invalid.

Source

pub fn feature_comments<'tree>( &'tree self, feature: &Feature<'tree>, ) -> Vec<&'tree str>

Given a Feature, return all comments that span the same range as the feature does.

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> 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 = Infallible

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.