Skip to main content

from_str_with_config

Function from_str_with_config 

Source
pub fn from_str_with_config<T>(s: &str, config: &ParserConfig) -> Result<T>
where T: for<'de> Deserialize<'de> + 'static,
Expand description

Deserialize YAML from a &str with a custom ParserConfig.

Use this when the defaults need overriding — common reasons: untrusted input (ParserConfig::strict()), pipeline-specific limits (ParserConfig::max_depth), YAML 1.1 compatibility (ParserConfig::version), or custom safe-YAML policy::Policy enforcement.

§Errors

Same variant set as from_str. The active config controls which limit-related errors can fire:

  • When config.duplicate_key_policy == DuplicateKeyPolicy::Error, any duplicate mapping key returns Error::DuplicateKey.
  • When the input exceeds the configured max_depth, max_document_length, max_alias_expansions, max_mapping_keys, or max_sequence_length, the matching Error::*Limit variant is returned.
  • When config.policies contains a policy that rejects the document, Error::Deserialize is returned with the policy’s diagnostic.

§Examples

use noyalib::{from_str_with_config, ParserConfig};
let cfg = ParserConfig::strict();
let n: i32 = from_str_with_config("7", &cfg).unwrap();
assert_eq!(n, 7);