Skip to main content

DocumentResolvedExt

Trait DocumentResolvedExt 

Source
pub trait DocumentResolvedExt {
    // Required methods
    fn get_resolved(&self, key: impl AsYaml) -> Option<YamlValue>;
    fn build_anchor_registry(&self) -> AnchorRegistry;
}
Expand description

Extension trait for Document to support resolved lookups

Required Methods§

Source

fn get_resolved(&self, key: impl AsYaml) -> Option<YamlValue>

Get a value with anchor/alias resolution

This method resolves aliases (*alias) to their anchored values (&anchor), and supports merge keys (<<) for combining mappings.

§Examples
use yaml_edit::Document;
use yaml_edit::anchor_resolution::DocumentResolvedExt;
use std::str::FromStr;

let yaml = r#"
config: &cfg
  port: 8080
server: *cfg
"#;
let doc = Document::from_str(yaml).unwrap();

// Get with resolution - expands the *cfg alias
if let Some(resolved_value) = doc.get_resolved("server") {
    if let Some(server) = resolved_value.as_mapping() {
        if let Some(port) = server.get("port") {
            assert_eq!(port.to_i64(), Some(8080));
        }
    }
}
Source

fn build_anchor_registry(&self) -> AnchorRegistry

Build the anchor registry for this document

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§