Skip to main content

ParserConfig

Struct ParserConfig 

Source
#[non_exhaustive]
pub struct ParserConfig {
Show 38 fields pub yaml_version: YamlVersion, pub max_depth: usize, pub max_document_length: usize, pub max_stream_bytes: usize, pub max_alias_expansions: usize, pub max_mapping_keys: usize, pub max_sequence_length: usize, pub max_events: usize, pub max_nodes: usize, pub max_total_scalar_bytes: usize, pub max_documents: usize, pub max_merge_keys: usize, pub alias_anchor_ratio: Option<f64>, pub duplicate_key_policy: DuplicateKeyPolicy, pub strict_booleans: bool, pub legacy_booleans: bool, pub tag_registry: Option<Arc<TagRegistry>>, pub merge_key_policy: MergeKeyPolicy, pub no_schema: bool, pub legacy_octal_numbers: bool, pub ignore_binary_tag_for_string: bool, pub plain_scalar_strings: bool, pub legacy_sexagesimal: bool, pub lossless_u64_integers: bool, pub leading_zero_integer_strings: bool, pub legacy_binary_numbers: bool, pub float_overflow_strings: bool, pub integer_overflow_errors: bool, pub non_scalar_key_policy: NonScalarKeyPolicy, pub alias_jump_event_factor: Option<usize>, pub require_indent: RequireIndent, pub policies: Vec<Arc<dyn Policy>>, pub properties: Option<Arc<HashMap<String, String>>>, pub strict_properties: bool, pub include_resolver: Option<IncludeResolver>, pub max_include_depth: usize, pub max_include_sources: usize, pub max_total_include_bytes: usize, /* private fields */
}
Expand description

Deserialization configuration.

All fields are public, but the struct is annotated #[non_exhaustive] so that adding a new budget or policy in a future minor release is not a breaking change. Construct with ParserConfig::new / ParserConfig::strict / ParserConfig::default (preferred) or with the ..ParserConfig::default() struct-update form; do not construct from an exhaustive struct-literal outside this crate.

§Examples

use noyalib::ParserConfig;
let cfg = ParserConfig::new().max_depth(64);
assert_eq!(cfg.max_depth, 64);

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§yaml_version: YamlVersion

Which YAML specification version to honour during plain-scalar resolution.

YAML 1.2 (default) follows the core schema — strict true/false booleans, no bare 0-prefix octal, no sexagesimal 60:00 integers. YAML 1.1 broadens the resolver to accept all of those legacy forms.

Setting this to YamlVersion::V1_1 is equivalent to flipping every legacy_* flag (legacy_booleans, legacy_octal_numbers, legacy_sexagesimal) on at once. The legacy_* flags remain available for fine-grained overrides — version selection sets a preset, individual flags refine it.

§max_depth: usize

Maximum recursion depth allowed during parsing (default: 128).

§max_document_length: usize

Maximum length of a single YAML document in bytes (default: 64 MB).

§max_stream_bytes: usize

Maximum total byte length of a multi-document stream (default: 256 MB). Async multi-document readers enforce this before splitting, while each document remains subject to Self::max_document_length.

§max_alias_expansions: usize

Maximum number of times a single anchor can be expanded (default: 1024).

§max_mapping_keys: usize

Maximum number of keys allowed in a single mapping (default: 64k).

§max_sequence_length: usize

Maximum number of elements allowed in a single sequence (default: 64k).

§max_events: usize

Maximum total parser events emitted across the input (default: 1 000 000). Caps event-stream amplification independent of recursion depth or alias count. Trips crate::Error::Budget with crate::BudgetBreach::MaxEvents.

§max_nodes: usize

Maximum total Value nodes authored into the AST across the input (default: 250 000). Each scalar, sequence, and mapping — empty collections included — counts as one node, so this bounds node-dense payloads (long runs of []/{}) that stay under the scalar-byte and event caps. Trips crate::Error::Budget with crate::BudgetBreach::MaxNodes. Enforced on the AST-loader path and re-applied to the fully expanded include graph; raise it for deliberately large documents.

§max_total_scalar_bytes: usize

Maximum cumulative scalar-byte count across the document (default: 64 MB). Distinct from Self::max_document_length (input size) — this caps scalar payload after alias expansion. Trips crate::BudgetBreach::MaxTotalScalarBytes.

§max_documents: usize

Maximum number of documents in a multi-document stream (default: 1 000). Trips crate::BudgetBreach::MaxDocuments.

§max_merge_keys: usize

Maximum number of merge-key (<<) entries across the document (default: 10 000). Trips crate::BudgetBreach::MaxMergeKeys.

§alias_anchor_ratio: Option<f64>

Optional alias-to-anchor ratio heuristic for detecting billion-laughs amplification patterns (default: Some(10.0)). When more than ratio × anchors aliases have been resolved, the parser trips crate::BudgetBreach::AliasAnchorRatio. Set to None to disable.

§duplicate_key_policy: DuplicateKeyPolicy

How to handle duplicate keys in a mapping (default: Last, per YAML 1.2).

§strict_booleans: bool

If true, only true and false (lowercase) are accepted as booleans.

§legacy_booleans: bool

If true, accepts YAML 1.1 booleans like yes, no, on, off.

§tag_registry: Option<Arc<TagRegistry>>

Optional registry of custom tags to strip on the streaming path.

See TagRegistry for the full rationale. None (default) preserves the legacy behaviour of routing every custom-tagged value through the AST fallback.

§merge_key_policy: MergeKeyPolicy

How the YAML merge key (<<) should be handled.

See MergeKeyPolicy for the available policies. The default is MergeKeyPolicy::Auto — the YAML 1.2 spec behaviour where <<: triggers automatic mapping merge.

§no_schema: bool

When true, plain scalars are never resolved to null / bool / int / float — every plain scalar becomes a string. Useful for schema-strict pipelines that require the user to quote intent explicitly. Default false.

§legacy_octal_numbers: bool

When true, accept YAML 1.1-style bare 0-prefix octal literals (e.g. 0644 parsed as 420) in addition to the YAML 1.2 0o644 form. Default false to honour the YAML 1.2 schema.

§ignore_binary_tag_for_string: bool

When true, deserializing !!binary "ABCD" into a String target yields the literal base64 source string ("ABCD") rather than rejecting on tag mismatch. The canonical bytes path (Vec<u8>, serde_bytes::ByteBuf) still decodes the base64 payload either way. Useful for migrations from Python pyyaml-style applications that treat the tag as advisory. Default false.

§plain_scalar_strings: bool

When enabled, a plain scalar deserializes into a String (or char) target as its source text even where the YAML 1.2 schema resolves it to a number, boolean, or null: password: 123456 gives "123456", ~ gives "~", an empty value gives "". Off by default: a String field refuses a non-string plain scalar. Quoted scalars are strings either way. Matches what serde_yaml did for typed targets.

§legacy_sexagesimal: bool

When true, accept YAML 1.1-style sexagesimal numbers (60:00, 1:30:00) as integers. The colon-separated digits are interpreted in base 60: each component is multiplied by an increasing power of 60, summed left to right. 60:00 → 3 600; 1:30:00 → 5 400. Negative values (-1:30:00) and partial signs are honoured.

Off by default to honour the YAML 1.2 schema. Useful for migrations from YAML 1.1 / Ruby / pyyaml configs that use the legacy time-of-day notation.

§lossless_u64_integers: bool

When true, and the lossless-u64 Cargo feature is enabled, YAML integer scalars in (i64::MAX, u64::MAX] resolve as unsigned integers instead of falling through to f64.

Default false to preserve the historical public Integer(i64) / Float(f64) model and serde-yaml compatibility.

§leading_zero_integer_strings: bool

When true, a plain decimal integer with a leading zero (0123, +007) resolves as a string instead of a number. This is what serde_yaml 0.9 (libyaml) did — the spelling is octal in YAML 1.1 and decimal in 1.2, and libyaml sidestepped the ambiguity by resolving neither. 0, 0o755, and 0x1F are unaffected. Default false (YAML 1.2: a decimal integer).

§legacy_binary_numbers: bool

When true, accept YAML 1.1-style binary literals (0b11 → 3). Default false to honour the YAML 1.2 schema, which has no binary form.

§float_overflow_strings: bool

When true, a plain scalar float whose literal spelling overflows f64 (1e999) resolves as a string instead of infinity. The explicit spellings .inf / -.Inf / .nan still resolve to their float values. Matches serde_yaml 0.9. Default false (overflow saturates to infinity, the Rust float-parsing convention).

§integer_overflow_errors: bool

When true, a plain decimal integer beyond u64::MAX (18446744073709551616) aborts the parse with ErrorKind::IntegerOverflow instead of falling through to an approximate f64. Matches serde_yaml 0.9’s “JSON number out of range”. Default false.

§non_scalar_key_policy: NonScalarKeyPolicy

What to do with a non-scalar mapping key ([a, b]: v, {k: v}: w). See NonScalarKeyPolicy. Default NonScalarKeyPolicy::Stringify — the key is converted to its deterministic string form.

§alias_jump_event_factor: Option<usize>

Transitive alias-expansion budget as a multiple of the document’s own event count, mirroring serde_yaml 0.9’s rule (its deserializer refuses once alias jumps exceed events × 100 with “repetition limit exceeded”). Each alias expansion charges the full node count of the anchored subtree, so nested anchors multiply. None (default) disables the factor check; the absolute Self::max_alias_expansions and byte budgets still apply.

§require_indent: RequireIndent

Indentation-validation mode. See RequireIndent. Default: RequireIndent::Unchecked — accept any well-formed YAML indent.

§policies: Vec<Arc<dyn Policy>>

Pluggable “Safe YAML” policies, run during parsing.

Each Policy inspects parser events and the post-parse Value tree; any policy returning Err(...) aborts the parse with that diagnostic. Empty by default.

Use ParserConfig::with_policy to register a policy. When at least one policy is present the streaming fast-path is bypassed automatically so the policy contract holds for every code path.

§properties: Option<Arc<HashMap<String, String>>>

${KEY} / ${KEY:-default} substitution table consulted after parsing every document.

Each scalar in the resulting Value tree is walked and any ${name} placeholder is replaced with the property of that name. Supported syntax:

  • ${name} — substitute, error or pass through depending on Self::strict_properties
  • ${name:-default} — substitute, falling back to default when name is missing (always silent, never surfaces in errors)
  • ${{ — literal ${ (escape for the open delimiter)
  • $$ — literal $
  • }} — literal }

None (default) disables the substitution pass entirely; the parser is unchanged. Setting a non-empty map forces the AST fallback so the post-parse walk runs uniformly across every typed target.

§strict_properties: bool

When true, an unknown ${name} placeholder (no entry in Self::properties and no :-default fallback) aborts the parse with Error::Custom. When false (default), unknown placeholders are replaced with the empty string — the lossy semantics matching Value::interpolate_properties_lossy.

§include_resolver: Option<IncludeResolver>

!include directive resolver. When set, the post-parse walk substitutes every Value::Tagged(!include, spec) node with the result of resolver(IncludeRequest). See crate::include::IncludeResolver for the closure signature and crate::include::SafeFileResolver for the bundled filesystem implementation.

None (default) disables include expansion; tagged !include nodes flow through unchanged.

§max_include_depth: usize

Maximum !include recursion depth. Default 24. Each nested !include increments the depth counter; once the limit is reached, the parser aborts with Error::RecursionLimitExceeded. Pairs with a per-walk visited-set to catch cycles independent of depth.

§max_include_sources: usize

Maximum number of sources resolved during one include walk. Default 256.

§max_total_include_bytes: usize

Maximum cumulative bytes returned by include resolvers during one include walk. Default 64 MiB.

Implementations§

Source§

impl ParserConfig

Source

pub fn new() -> Self

Create a new configuration with default values.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new();
assert_eq!(cfg.max_depth, 128);
Source

pub fn profile(profile: ParserProfile) -> Self

Create a configuration from a stable named profile.

Profiles make trust-boundary configuration explicit and keep callers independent from the individual fields that compose each baseline. Builder methods can refine the returned configuration.

§Examples
use noyalib::{ParserConfig, ParserProfile};

let cfg = ParserConfig::profile(ParserProfile::Strict)
    .max_document_length(32 * 1024);
assert_eq!(cfg.max_document_length, 32 * 1024);
Source

pub fn strict() -> Self

Create a strict configuration (YAML 1.2 strict) with tighter security limits suitable for untrusted input.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::strict();
assert_eq!(cfg.max_depth, 64);
Source

pub fn serde_yaml_compat() -> Self

Create the configuration the compat-serde-yaml shim uses: noyalib’s defaults with every knob turned to reproduce serde_yaml 0.9’s observable behaviour on the same input — the behavioural half of being a drop-in replacement.

Concretely, relative to ParserConfig::new:

  • << merge keys stay ordinary entries whose alias values resolve (MergeKeyPolicy::AsOrdinary) — serde_yaml never implemented the merge;
  • leading-zero integers (0123) resolve as strings and YAML 1.1 binary literals (0b11) as integers — libyaml’s resolver, spec versions notwithstanding;
  • a literal float overflow (1e999) is a string, not infinity;
  • integers past u64::MAX error (“JSON number out of range” territory) instead of degrading to f64, and (with the lossless-u64 feature the shim enables) u64-range integers keep full precision;
  • a non-scalar mapping key is an error, not a stringified key;
  • transitive alias expansion is budgeted at 100× the document’s event count — the exact rule behind serde_yaml’s “repetition limit exceeded”.
§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::serde_yaml_compat();
assert!(cfg.leading_zero_integer_strings);
assert_eq!(cfg.alias_jump_event_factor, Some(100));
Source

pub fn limits(&self) -> ParserLimits

Return the resource budgets currently applied to this configuration.

Semantic settings, policies, property interpolation, tag registries, and include resolvers are deliberately excluded.

Source

pub fn with_limits(self, limits: ParserLimits) -> Self

Replace every resource budget while preserving semantic settings and installed integrations.

§Examples
use noyalib::{ParserConfig, ParserLimits, YamlVersion};

let cfg = ParserConfig::new()
    .version(YamlVersion::V1_1)
    .with_limits(ParserLimits::strict());
assert_eq!(cfg.yaml_version, YamlVersion::V1_1);
assert_eq!(cfg.max_depth, 64);
Source

pub fn properties(self, properties: Arc<HashMap<String, String>>) -> Self

Install a ${KEY} substitution table consulted after parsing.

Each scalar in the resulting Value tree is walked and any ${name} placeholder is replaced with the property of that name. Pairs with Self::strict_properties to choose between erroring or silently empty-substituting on unknown keys, and with ${name:-default} syntax for inline defaults.

§Examples
use noyalib::{from_str_with_config, ParserConfig, Value};
use std::collections::HashMap;
use std::sync::Arc;

let mut props = HashMap::new();
props.insert("HOST".to_string(), "localhost".to_string());
let cfg = ParserConfig::new().properties(Arc::new(props));
let v: Value = from_str_with_config("url: http://${HOST}/", &cfg).unwrap();
assert_eq!(v["url"].as_str(), Some("http://localhost/"));
Source

pub fn strict_properties(self, strict: bool) -> Self

Toggle strict-mode placeholder resolution.

When true, an unknown ${name} (no map entry, no :-default fallback) aborts the parse. When false (default), unknown placeholders are replaced with the empty string — useful for environment-style configs where missing variables should silently degrade.

§Examples
use noyalib::{from_str_with_config, ParserConfig, Value};
use std::collections::HashMap;
use std::sync::Arc;

let cfg = ParserConfig::new()
    .properties(Arc::new(HashMap::new()))
    .strict_properties(true);
let res: Result<Value, _> = from_str_with_config("x: ${MISSING}", &cfg);
assert!(res.is_err());
Source

pub fn include_resolver(self, resolver: IncludeResolver) -> Self

Install an !include directive resolver.

Each Value::Tagged(!include, scalar_spec) node in the parsed tree is replaced with the resolver’s output. The resolver is consulted with an IncludeRequest carrying the verbatim spec text, a stable source-id, and the current recursion depth.

Pair with Self::max_include_depth to bound the recursion ceiling. Cycle detection (A includes B includes A) runs independently using a per-walk visited set.

§Examples
use noyalib::include::{IncludeRequest, IncludeResolver, InputSource};
use noyalib::{ParserConfig, Result};

let resolver = IncludeResolver::new(|req: IncludeRequest<'_>| -> Result<InputSource> {
    // For an in-memory test, fabricate a YAML payload
    // keyed on the spec.
    Ok(InputSource::new(req.spec, format!("name: {}\n", req.spec)))
});
let cfg = ParserConfig::new().include_resolver(resolver);
Source

pub fn max_include_depth(self, depth: usize) -> Self

Maximum !include recursion depth.

Default 24 (8 in Self::strict()). Each nested !include increments the depth; once the limit is reached, the parser aborts with Error::RecursionLimitExceeded. The cap is independent of Self::max_depth (which bounds YAML structural nesting) and of the per-walk cycle-detection set (which catches A→B→A regardless of depth).

Source

pub fn max_include_sources(self, max: usize) -> Self

Set the maximum number of sources resolved by one include walk.

Source

pub fn max_total_include_bytes(self, max: usize) -> Self

Set the cumulative byte budget for sources returned by include resolvers.

Source

pub fn version(self, version: YamlVersion) -> Self

Select the YAML specification version the resolver should honour.

Selecting YamlVersion::V1_1 is a preset over the three legacy_* flags — equivalent to:

cfg.legacy_booleans      = true;  // yes / no / on / off
cfg.legacy_octal_numbers = true;  // 0644 → octal
cfg.legacy_sexagesimal   = true;  // 60:00 → 3600

Selecting YamlVersion::V1_2 resets those three flags to false so callers can revert to strict 1.2 mode without re-creating the config from scratch. Other fields (limits, policies, merge-key behaviour) are unaffected.

Fine-grained overrides (e.g. “1.1 booleans but reject octal 0644”) work as expected: call version first, then flip individual flags.

§Examples
use noyalib::{from_str_with_config, ParserConfig, Value, YamlVersion};

let cfg = ParserConfig::new().version(YamlVersion::V1_1);
// YAML 1.1 booleans
let v: Value = from_str_with_config("on", &cfg).unwrap();
assert_eq!(v, Value::Bool(true));
// YAML 1.1 octal
let v: Value = from_str_with_config("0644", &cfg).unwrap();
assert_eq!(v, Value::from(420_i64));
// YAML 1.1 sexagesimal
let v: Value = from_str_with_config("1:30", &cfg).unwrap();
assert_eq!(v, Value::from(90_i64));
Source

pub fn with_policy<P>(self, policy: P) -> Self
where P: Policy + 'static,

Register a Policy to enforce during parsing.

Multiple policies may be registered; they all run in registration order, and the first error short-circuits the parse. When any policy is present the streaming fast-path is bypassed so the policy contract is enforced uniformly.

§Examples
use noyalib::{from_str_with_config, ParserConfig, Value};
use noyalib::policy::DenyAnchors;

let cfg = ParserConfig::new().with_policy(DenyAnchors);
let res: Result<Value, _> =
    from_str_with_config("a: &x 1\nb: *x\n", &cfg);
assert!(res.is_err());
Source

pub fn max_depth(self, depth: usize) -> Self

Set the maximum recursion depth.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new().max_depth(32);
assert_eq!(cfg.max_depth, 32);
Source

pub fn max_document_length(self, len: usize) -> Self

Set the maximum document length.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new().max_document_length(1024);
assert_eq!(cfg.max_document_length, 1024);
Source

pub fn max_alias_expansions(self, expansions: usize) -> Self

Set the maximum alias expansions.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new().max_alias_expansions(50);
assert_eq!(cfg.max_alias_expansions, 50);
Source

pub fn max_mapping_keys(self, max: usize) -> Self

Set the maximum number of mapping keys.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new().max_mapping_keys(100);
assert_eq!(cfg.max_mapping_keys, 100);
Source

pub fn max_sequence_length(self, max: usize) -> Self

Set the maximum sequence length.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new().max_sequence_length(100);
assert_eq!(cfg.max_sequence_length, 100);
Source

pub fn max_events(self, max: usize) -> Self

Set the maximum total parser-event budget.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new().max_events(50_000);
assert_eq!(cfg.max_events, 50_000);
Source

pub fn max_nodes(self, max: usize) -> Self

Set the maximum total Value node budget.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new().max_nodes(10_000);
assert_eq!(cfg.max_nodes, 10_000);
Source

pub fn max_total_scalar_bytes(self, max: usize) -> Self

Set the maximum cumulative scalar-byte budget.

Distinct from Self::max_document_length — this caps scalar bytes after alias expansion.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new().max_total_scalar_bytes(8 * 1024 * 1024);
assert_eq!(cfg.max_total_scalar_bytes, 8 * 1024 * 1024);
Source

pub fn max_documents(self, max: usize) -> Self

Set the maximum document count for multi-document streams.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new().max_documents(64);
assert_eq!(cfg.max_documents, 64);
Source

pub fn max_stream_bytes(self, max: usize) -> Self

Set the maximum total byte length of a multi-document stream.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new().max_stream_bytes(8 * 1024 * 1024);
assert_eq!(cfg.max_stream_bytes, 8 * 1024 * 1024);
Source

pub fn max_merge_keys(self, max: usize) -> Self

Set the maximum merge-key count budget.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new().max_merge_keys(1_000);
assert_eq!(cfg.max_merge_keys, 1_000);
Source

pub fn require_indent(self, mode: RequireIndent) -> Self

Set the indentation-validation mode.

§Examples
use noyalib::{ParserConfig, RequireIndent};
let cfg = ParserConfig::new().require_indent(RequireIndent::Even);
assert_eq!(cfg.require_indent, RequireIndent::Even);
Source

pub fn alias_anchor_ratio(self, ratio: Option<f64>) -> Self

Set the alias-to-anchor ratio heuristic.

Pass Some(ratio) to enable the billion-laughs guard, None to disable.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new().alias_anchor_ratio(Some(20.0));
assert_eq!(cfg.alias_anchor_ratio, Some(20.0));
Source

pub fn duplicate_key_policy(self, policy: DuplicateKeyPolicy) -> Self

Set the duplicate key policy.

§Examples
use noyalib::{DuplicateKeyPolicy, ParserConfig};
let cfg = ParserConfig::new().duplicate_key_policy(DuplicateKeyPolicy::Error);
assert_eq!(cfg.duplicate_key_policy, DuplicateKeyPolicy::Error);
Source

pub fn strict_booleans(self, strict: bool) -> Self

Enable or disable strict booleans.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new().strict_booleans(true);
assert!(cfg.strict_booleans);
Source

pub fn legacy_booleans(self, legacy: bool) -> Self

Enable or disable legacy booleans.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new().legacy_booleans(true);
assert!(cfg.legacy_booleans);
Source

pub fn tag_registry(self, registry: Arc<TagRegistry>) -> Self

Attach a TagRegistry so the streaming deserializer strips listed custom tags instead of routing them through the AST.

See the tag_registry module documentation for when to use this versus #[serde(rename)].

§Examples
use noyalib::{ParserConfig, TagRegistry};
use std::sync::Arc;
let reg = Arc::new(TagRegistry::new().with("!Celsius"));
let cfg = ParserConfig::new().tag_registry(Arc::clone(&reg));
assert!(cfg.tag_registry.is_some());
Source

pub fn merge_key_policy(self, policy: MergeKeyPolicy) -> Self

Set the policy for handling the YAML merge key (<<).

§Examples
use noyalib::{MergeKeyPolicy, ParserConfig};
let cfg = ParserConfig::new().merge_key_policy(MergeKeyPolicy::AsOrdinary);
assert_eq!(cfg.merge_key_policy, MergeKeyPolicy::AsOrdinary);
Source

pub fn no_schema(self, no_schema: bool) -> Self

Toggle schema-free plain-scalar resolution. When true, every plain scalar becomes a string regardless of whether it would normally resolve to null, bool, integer, or float.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new().no_schema(true);
assert!(cfg.no_schema);
Source

pub fn legacy_octal_numbers(self, on: bool) -> Self

Toggle YAML 1.1-style bare 0-prefix octal parsing (e.g. 0644 → 420). Off by default; YAML 1.2 requires the 0o prefix.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new().legacy_octal_numbers(true);
assert!(cfg.legacy_octal_numbers);
Source

pub fn ignore_binary_tag_for_string(self, on: bool) -> Self

Toggle the migration-helper behaviour where !!binary "ABCD" deserializes into a String target as the literal base64 source string. The canonical bytes path (Vec<u8>, serde_bytes::ByteBuf) is unaffected — it always decodes the base64 payload.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new().ignore_binary_tag_for_string(true);
assert!(cfg.ignore_binary_tag_for_string);
Source

pub fn plain_scalar_strings(self, on: bool) -> Self

When enabled, a plain scalar deserializes into a String (or char) target as its source text even where the YAML 1.2 schema resolves it to a number, boolean, or null: password: 123456 gives "123456", ~ gives "~", an empty value gives "". Off by default: a String field refuses a non-string plain scalar. Quoted scalars are strings either way. Matches what serde_yaml did for typed targets.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new().plain_scalar_strings(true);
assert!(cfg.plain_scalar_strings);
Source

pub fn legacy_sexagesimal(self, on: bool) -> Self

Toggle YAML 1.1-style sexagesimal number parsing (60:00 → 3 600). Off by default; YAML 1.2 dropped the sexagesimal schema, so plain 1:30:00 would otherwise surface as a string.

§Examples
use noyalib::ParserConfig;
let cfg = ParserConfig::new().legacy_sexagesimal(true);
assert!(cfg.legacy_sexagesimal);
Source

pub fn lossless_u64_integers(self, on: bool) -> Self

Enable or disable lossless unsigned integer resolution.

With the lossless-u64 feature enabled, setting this to true lets YAML integer scalars in (i64::MAX, u64::MAX] resolve as Number::Unsigned instead of falling through to Number::Float.

Trait Implementations§

Source§

impl Clone for ParserConfig

Source§

fn clone(&self) -> ParserConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ParserConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ParserConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> MaybeSendSync for T

§

impl<D> OwoColorize for D

§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either [OwoColorize::fg] or a color-specific method, such as [OwoColorize::green], Read more
§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either [OwoColorize::bg] or a color-specific method, such as [OwoColorize::on_yellow], Read more
§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
§

impl<T> Paint for T
where T: ?Sized,

§

fn fg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the foreground set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like red() and green(), which have the same functionality but are pithier.

§Example

Set foreground color to white using fg():

use yansi::{Paint, Color};

painted.fg(Color::White);

Set foreground color to white using white().

use yansi::Paint;

painted.white();
§

fn primary(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Primary].

§Example
println!("{}", value.primary());
§

fn fixed(&self, color: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Fixed].

§Example
println!("{}", value.fixed(color));
§

fn rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Rgb].

§Example
println!("{}", value.rgb(r, g, b));
§

fn black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Black].

§Example
println!("{}", value.black());
§

fn red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Red].

§Example
println!("{}", value.red());
§

fn green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Green].

§Example
println!("{}", value.green());
§

fn yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Yellow].

§Example
println!("{}", value.yellow());
§

fn blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Blue].

§Example
println!("{}", value.blue());
§

fn magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Magenta].

§Example
println!("{}", value.magenta());
§

fn cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Cyan].

§Example
println!("{}", value.cyan());
§

fn white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: White].

§Example
println!("{}", value.white());
§

fn bright_black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlack].

§Example
println!("{}", value.bright_black());
§

fn bright_red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightRed].

§Example
println!("{}", value.bright_red());
§

fn bright_green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightGreen].

§Example
println!("{}", value.bright_green());
§

fn bright_yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightYellow].

§Example
println!("{}", value.bright_yellow());
§

fn bright_blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlue].

§Example
println!("{}", value.bright_blue());
§

fn bright_magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.bright_magenta());
§

fn bright_cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightCyan].

§Example
println!("{}", value.bright_cyan());
§

fn bright_white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightWhite].

§Example
println!("{}", value.bright_white());
§

fn bg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the background set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like on_red() and on_green(), which have the same functionality but are pithier.

§Example

Set background color to red using fg():

use yansi::{Paint, Color};

painted.bg(Color::Red);

Set background color to red using on_red().

use yansi::Paint;

painted.on_red();
§

fn on_primary(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Primary].

§Example
println!("{}", value.on_primary());
§

fn on_fixed(&self, color: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Fixed].

§Example
println!("{}", value.on_fixed(color));
§

fn on_rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Rgb].

§Example
println!("{}", value.on_rgb(r, g, b));
§

fn on_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Black].

§Example
println!("{}", value.on_black());
§

fn on_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Red].

§Example
println!("{}", value.on_red());
§

fn on_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Green].

§Example
println!("{}", value.on_green());
§

fn on_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Yellow].

§Example
println!("{}", value.on_yellow());
§

fn on_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Blue].

§Example
println!("{}", value.on_blue());
§

fn on_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Magenta].

§Example
println!("{}", value.on_magenta());
§

fn on_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Cyan].

§Example
println!("{}", value.on_cyan());
§

fn on_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: White].

§Example
println!("{}", value.on_white());
§

fn on_bright_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlack].

§Example
println!("{}", value.on_bright_black());
§

fn on_bright_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightRed].

§Example
println!("{}", value.on_bright_red());
§

fn on_bright_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightGreen].

§Example
println!("{}", value.on_bright_green());
§

fn on_bright_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightYellow].

§Example
println!("{}", value.on_bright_yellow());
§

fn on_bright_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlue].

§Example
println!("{}", value.on_bright_blue());
§

fn on_bright_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.on_bright_magenta());
§

fn on_bright_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightCyan].

§Example
println!("{}", value.on_bright_cyan());
§

fn on_bright_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightWhite].

§Example
println!("{}", value.on_bright_white());
§

fn attr(&self, value: Attribute) -> Painted<&T>

Enables the styling [Attribute] value.

This method should be used rarely. Instead, prefer to use attribute-specific builder methods like bold() and underline(), which have the same functionality but are pithier.

§Example

Make text bold using attr():

use yansi::{Paint, Attribute};

painted.attr(Attribute::Bold);

Make text bold using using bold().

use yansi::Paint;

painted.bold();
§

fn bold(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Bold].

§Example
println!("{}", value.bold());
§

fn dim(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Dim].

§Example
println!("{}", value.dim());
§

fn italic(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Italic].

§Example
println!("{}", value.italic());
§

fn underline(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Underline].

§Example
println!("{}", value.underline());

Returns self with the attr() set to [Attribute :: Blink].

§Example
println!("{}", value.blink());

Returns self with the attr() set to [Attribute :: RapidBlink].

§Example
println!("{}", value.rapid_blink());
§

fn invert(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Invert].

§Example
println!("{}", value.invert());
§

fn conceal(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Conceal].

§Example
println!("{}", value.conceal());
§

fn strike(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Strike].

§Example
println!("{}", value.strike());
§

fn quirk(&self, value: Quirk) -> Painted<&T>

Enables the yansi [Quirk] value.

This method should be used rarely. Instead, prefer to use quirk-specific builder methods like mask() and wrap(), which have the same functionality but are pithier.

§Example

Enable wrapping using .quirk():

use yansi::{Paint, Quirk};

painted.quirk(Quirk::Wrap);

Enable wrapping using wrap().

use yansi::Paint;

painted.wrap();
§

fn mask(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Mask].

§Example
println!("{}", value.mask());
§

fn wrap(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Wrap].

§Example
println!("{}", value.wrap());
§

fn linger(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Linger].

§Example
println!("{}", value.linger());
§

fn clear(&self) -> Painted<&T>

👎Deprecated since 1.0.1:

renamed to resetting() due to conflicts with Vec::clear(). The clear() method will be removed in a future release.

Returns self with the quirk() set to [Quirk :: Clear].

§Example
println!("{}", value.clear());
§

fn resetting(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Resetting].

§Example
println!("{}", value.resetting());
§

fn bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Bright].

§Example
println!("{}", value.bright());
§

fn on_bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: OnBright].

§Example
println!("{}", value.on_bright());
§

fn whenever(&self, value: Condition) -> Painted<&T>

Conditionally enable styling based on whether the [Condition] value applies. Replaces any previous condition.

See the crate level docs for more details.

§Example

Enable styling painted only when both stdout and stderr are TTYs:

use yansi::{Paint, Condition};

painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);
§

fn new(self) -> Painted<Self>
where Self: Sized,

Create a new [Painted] with a default [Style]. Read more
§

fn paint<S>(&self, style: S) -> Painted<&Self>
where S: Into<Style>,

Apply a style wholesale to self. Any previous style is replaced. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.