taffy/value

The YamlValue type and direct accessors. Most users want the re-exports on the top-level taffy module; this module is exposed for pattern-matching (value.Null, value.Mapping(_)) and for direct YamlValue construction in tests.

Types

Note on Mapping: pairs are stored in YAML insertion order. Taffy does not currently reject duplicate keys (YAML 1.2 says it should — this is a known gap). When duplicates exist, get / get_path return the first match while as_dict collapses to last-wins.

pub type YamlValue {
  Null
  Bool(Bool)
  Int(Int)
  Float(Float)
  String(String)
  Sequence(List(YamlValue))
  Mapping(List(#(String, YamlValue)))
}

Constructors

  • Null
  • Bool(Bool)
  • Int(Int)
  • Float(Float)
  • String(String)
  • Sequence(List(YamlValue))
  • Mapping(List(#(String, YamlValue)))

Values

pub fn as_bool(value: YamlValue) -> option.Option(Bool)
pub fn as_dict(
  value: YamlValue,
) -> option.Option(dict.Dict(String, YamlValue))
pub fn as_float(value: YamlValue) -> option.Option(Float)
pub fn as_int(value: YamlValue) -> option.Option(Int)
pub fn as_list(
  value: YamlValue,
) -> option.Option(List(YamlValue))
pub fn as_pairs(
  value: YamlValue,
) -> option.Option(List(#(String, YamlValue)))
pub fn as_string(value: YamlValue) -> option.Option(String)
pub fn get(
  value: YamlValue,
  key: String,
) -> option.Option(YamlValue)
pub fn index(
  value: YamlValue,
  idx: Int,
) -> option.Option(YamlValue)
pub fn is_null(value: YamlValue) -> Bool
pub fn size(value: YamlValue) -> Int

Count the total number of nodes in a value tree (including the root). Used by the parser to budget alias expansion against billion-laughs attacks; exposed so callers can apply their own size policies.

pub fn to_string(value: YamlValue) -> String
pub fn to_yaml(value: YamlValue) -> String

Emit a value as block-style YAML. The output ends with a trailing newline. Strings are quoted only when they would otherwise be parsed as a different scalar type (numbers, booleans, null) or contain characters that aren’t safe to render plain.

Search Document