Skip to main content

nmbrs_workload/
lib.rs

1// Copyright 2024-2026 Jonathan Shook
2// SPDX-License-Identifier: Apache-2.0
3
4//! # nmbrs-workload
5//!
6//! Contract & axioms: [SRD 25](../../docs/SRD/25_workload_contract.md).
7//!
8//! Workload specification parsing and processing for nmbrs. Owns
9//! the YAML schema definition (op templates, bindings, phases,
10//! scenarios, tags, parameter inheritance) plus the inline
11//! `op='...'` shorthand the CLI accepts in place of a workload
12//! file.
13//!
14//! The crate's deliberately one-way: it parses YAML / inline
15//! shorthand into a [`model::Workload`] tree and exposes helpers
16//! to extract bind-points, tag-filter ops, and resolve template
17//! parameters. It does not execute anything — that's
18//! `nmbrs-runtime`'s job.
19//!
20//! ## Pieces
21//!
22//! - [`model`] — the parsed `Workload` AST. `Workload` →
23//!   `WorkloadPhase`s + ops + `ScenarioNode`s; an op carries its
24//!   field map plus parsed bindings.
25//! - [`parse`] — YAML → `Workload`, with phase-name preservation
26//!   and friendly error messages.
27//! - [`inline`] — `nmbrs run op='hello {{cycle}}'` synthesizer:
28//!   builds a one-op `Workload` from a single CLI string.
29//! - [`bindpoints`] — extracts `{name}`, `{{expr}}`, qualified
30//!   refs (`{input:cycle}`, `{capture:foo}`) from any string.
31//! - [`tags`] — `tags=block:main,phase:read` filters during op
32//!   selection.
33//! - [`template`] — `{param}` template substitution with
34//!   default-value support.
35//!
36//! ## Quick examples
37//!
38//! Bind-point extraction:
39//!
40//! ```
41//! use nmbrs_workload::bindpoints::{extract_bind_points, BindPoint, BindQualifier};
42//!
43//! let pts = extract_bind_points("INSERT INTO t VALUES ({id}, {{hash(cycle)}})")
44//!     .expect("well-formed bind points");
45//! assert_eq!(pts.len(), 2);
46//! assert!(matches!(
47//!     &pts[0],
48//!     BindPoint::Reference { name, qualifier: BindQualifier::None, .. } if name == "id",
49//! ));
50//! assert!(matches!(&pts[1], BindPoint::InlineDefinition(expr) if expr == "hash(cycle)"));
51//!
52//! // A `{name:<type>}` assertion names its type by polydat keyword.
53//! assert!(extract_bind_points("VALUES ({id:str})").is_ok());
54//! assert!(extract_bind_points("VALUES ({id:String})").is_err());
55//! ```
56//!
57//! Template substitution at workload-build time:
58//!
59//! ```
60//! use nmbrs_workload::template::expand_templates;
61//! use std::collections::HashMap;
62//!
63//! let mut params = HashMap::new();
64//! params.insert("table".into(), "users".into());
65//! let resolved = expand_templates(
66//!     "SELECT * FROM TEMPLATE(table,defaultvalue)",
67//!     &params,
68//! );
69//! assert_eq!(resolved, "SELECT * FROM users");
70//! ```
71//!
72//! ## See also
73//!
74//! - SRD 20 (`docs/SRD/20_workload_model.md`) — workload model
75//! - SRD 21 (`docs/SRD/21_parameters.md`) — parameter resolution
76//!   precedence
77//! - SRD 18 (`docs/SRD/18_control_flow.md`) — scenario-tree
78//!   constructs (`for_each`, `do_while`, `do_until`,
79//!   `for_combinations`)
80
81pub mod bindpoints;
82/// The one boolean spelling (`true` / `false`) for params, fields
83/// and env flags.
84pub mod boolean;
85/// SRD-85 bundled-workload catalog (embedded workloads,
86/// tiers, exact-name lookup).
87pub mod catalog;
88pub mod construction;
89/// SRD-109 driver manifests (`driver=<name>` → adapter + library
90/// + defaults).
91pub mod drivers;
92pub mod edit;
93pub mod extends;
94pub mod implements;
95pub mod inline;
96mod key_metric;
97pub mod magnitude;
98pub mod metric_format;
99pub mod model;
100pub mod op_templates;
101pub mod op_text;
102pub mod parse;
103pub mod polydat_matter;
104/// Type names a workload writes, resolved to polydat `PortType`s.
105pub mod port_types;
106pub mod report;
107pub mod report_synth;
108pub mod spectest;
109/// SRD-85 deep workload suggestions — the shared "did you mean"
110/// set over the local file hierarchy and the bundled catalog,
111/// used by completion and the resolver not-found paths.
112pub mod suggest;
113pub mod tags;
114pub mod template;
115pub mod verify;
116pub mod vocab;