pub struct Document { /* private fields */ }Expand description
Represents a queryable YAML document.
Implementations§
Source§impl Document
impl Document
Sourcepub fn new(source: impl Into<String>) -> Result<Self, QueryError>
pub fn new(source: impl Into<String>) -> Result<Self, QueryError>
Construct a new Document from the given YAML.
Sourcepub fn source(&self) -> &str
pub fn source(&self) -> &str
Return a view of the original YAML source that this document was loaded from.
Sourcepub fn root(&self) -> Feature<'_>
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.
Sourcepub fn range_spanned_by_comment(&self, start: usize, end: usize) -> bool
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.
Sourcepub fn offset_inside_comment(&self, offset: usize) -> bool
pub fn offset_inside_comment(&self, offset: usize) -> bool
Returns whether the given offset is within a comment node’s span.
Sourcepub fn query(&self, query: &Query) -> Result<Feature<'_>, QueryError>
pub fn query(&self, query: &Query) -> Result<Feature<'_>, QueryError>
Perform a query on the current document, returning a Feature
if the query succeeds.
Sourcepub fn extract(&self, feature: &Feature<'_>) -> &str
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.
Sourcepub fn extract_with_leading_whitespace(&self, feature: &Feature<'_>) -> &str
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.