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 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.