Expand description
Scrusted-yaml: validates, loads and resolves scripted-yaml files, YAML with small pieces of
logic in marked keys (key!:), with formulas written in FEEL (SPEC.md).
use scrusted_yaml::{MemoryFiles, ScrustedYaml, ResolveOptions, vars};
let files = MemoryFiles::from_pairs([("limits.yml", "$vars:\n plan: {}\nper_minute!: if vars.plan = \"pro\" then 600 else 60\n")]);
let scrusted = ScrustedYaml::builder().files(files).build().unwrap();
let document = scrusted.load("limits.yml").unwrap();
let value = document.resolve(&vars! { plan: "pro" }, &ResolveOptions::default()).unwrap();
assert_eq!(value.as_map().unwrap()["per_minute"], scrusted_feel::Value::from(600));Re-exports§
pub use api::AsVars;pub use api::FromValue;pub use api::Functions;pub use api::HostFunction;pub use api::IntoValue;pub use api::Marked;pub use api::Typed;pub use api::Vars;pub use document::Data;pub use document::Document;pub use document::MarkedKey;pub use document::ResolveError;pub use document::ResolveOptions;pub use document::TestResult;pub use files::DiskFiles;pub use files::Files;pub use files::MemoryFiles;pub use files::Source;pub use files::Templates;pub use marker::MarkerFn;pub use marker::MarkerOutput;pub use marker::Placeholder;pub use marker::placeholder;pub use problem::Problem;pub use problem::Severity;pub use source::HostFunctionDecl;pub use source::Input;pub use source::Variable;pub use scrusted_feel as feel;
Modules§
- api
- The typed side of the API (SPEC 5.6–5.8): variables from serde, results into any
Deserialize, typed host functions, and marked values by type. - checker
- Validation of one file (SPEC 5.3): keywords, markers, formula syntax, names, schema, cycles. It runs no marker function and computes no formula but schema rules on items written out.
- document
- A loaded file: its data with formulas kept as formulas, and the way to compute them (SPEC 5.4).
- files
- Where files come from (SPEC 5.2): the disk, memory, the bundled templates, or the application’s own source.
- marker
- What the application registers: marker functions (SPEC 4.6, 5.7).
- merged
- The merged form: a patch with its base applied, as one file that needs no base (SPEC 4.11).
Where a formula reads
base, the replaced entry is kept beside it under$base. - node
- The file as a tree: maps, lists and scalars, each with its place (SPEC 4.12). One arena holds a file and the files it extends, so a patch moves nodes by relinking them.
- patch
$extends: a patch applied to its base, which is changed in place (SPEC 4.11).- problem
- Problems: what is wrong with a file, where (SPEC 5.3).
- reader
- Reads YAML text into the tree, from
saphyr-parserevents (SPEC 4.12, 10): positions, duplicate keys, tags and merge keys are checked here. - resolution
- One call of
resolve: all variables in, all values out. Each formula is computed when first read, once (SPEC 4.4). - schema
$schemaand$dsl: which keys a file has (SPEC 4.10).- scope
- What a name in a formula stands for at a place in the file (SPEC 4.3).
- source
- One file as written: its tree after
$extends, and what its top$keys say (SPEC 4.2, 4.5, 4.7). Nothing is computed. - types
- Rust types from a
$schema(SPEC 13, milestone 8):scrusted-yaml types <file>. - yaml_
out - Writes values as YAML: block maps and lists, text quoted where YAML would read it otherwise.
Macros§
- vars
- Builds the variables of a resolve from
name: valuepairs; values are anythingserde::Serialize(SPEC 5.6).
Structs§
- Builder
- Builds a
ScrustedYaml. - Host
Error - What a host function or a marker’s value reports when it fails.
- Limits
- How far evaluation may go (SPEC 7).
- Scrusted
Yaml - Validates and loads scripted-yaml files.
Send + Sync + Clone.
Enums§
Traits§
- Host
Value - What a marker function returned when it is not a plain value: kept, and read only when a formula reads the marked key (SPEC 5.7).
Functions§
- to_
value - Any
serde::Serializeas a value.
Type Aliases§
- Map
- A map of values; key order is kept as written.