Struct yamlpath::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 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 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.

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 line_comment(&self, feature: &Feature<'_>) -> Option<&str>

Given a Feature, return the comment (if one exists) on the first line of the feature’s location.

This is not a fully general comment extraction API: it only extracts comments on matching lines.

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.