Skip to main content

from_str_borrowed_with_config

Function from_str_borrowed_with_config 

Source
pub fn from_str_borrowed_with_config<'a>(
    input: &'a str,
    user_config: &ParserConfig,
) -> Result<BorrowedValue<'a>>
Expand description

Parse YAML into a zero-copy BorrowedValue with custom security limits.

Same as from_str_borrowed but accepts a crate::ParserConfig so callers can tighten max_document_length, max_depth, and other limits for untrusted input.

§Errors

Returns an error when the input exceeds max_document_length, when the parser encounters invalid YAML, or when alias expansion exceeds ParserConfig::max_alias_expansions.

§Aliases

Anchors (&name) and aliases (*name) are eagerly resolved on the borrowed path. The anchored value is stored in a side-table keyed by name; each alias clones the value into the tree (string fields stay Cow::Borrowed, so the clone is mostly free — only sequences and mappings actually duplicate). Total expansions are bounded by max_alias_expansions to neutralise YAML bombs.

§Examples

use noyalib::{borrowed::from_str_borrowed_with_config, ParserConfig};
let cfg = ParserConfig::strict();
let v = from_str_borrowed_with_config("k: 1\n", &cfg).unwrap();
assert!(v.as_mapping().is_some());