Skip to main content

pred

Macro pred 

Source
macro_rules! pred {
    (exists $key:literal) => { ... };
    (equals $key:literal, $value:expr) => { ... };
    (num_at_least $key:literal, $t:expr) => { ... };
    (num_at_most $key:literal, $t:expr) => { ... };
    (num_in_range $key:literal, $min:expr, $max:expr) => { ... };
    (semver_at_least $key:literal, $v:expr) => { ... };
    (semver_at_most $key:literal, $v:expr) => { ... };
    (semver_compatible $key:literal, $v:expr) => { ... };
    (prefix $key:literal, $p:expr) => { ... };
    (matches $key:literal, $p:expr) => { ... };
    (metadata_exists $key:expr) => { ... };
    (metadata_equals $key:expr, $v:expr) => { ... };
    (metadata_matches $key:expr, $p:expr) => { ... };
    (metadata_num_at_least $key:expr, $t:expr) => { ... };
    (and [ $($clause:expr),* $(,)? ]) => { ... };
    (or [ $($clause:expr),* $(,)? ]) => { ... };
    (not $clause:expr) => { ... };
}
Expand description

Lightweight macro sugar over Predicate constructors. Mirrors the substrate plan’s macro-style examples in §6a; lowers to plain constructor calls so the AST stays the single source of truth.

§Forms

pred!(exists "hardware.gpu");
pred!(equals "software.runtime", "cuda-12.4");
pred!(num_at_least "hardware.gpu.vram_gb", 24.0);
pred!(num_at_most "hardware.gpu.vram_gb", 80.0);
pred!(num_in_range "hardware.cpu_cores", 8.0, 64.0);
pred!(semver_at_least "software.runtime", "12.0");
pred!(semver_compatible "software.runtime", "12.0");
pred!(prefix "software.tool", "ffmpeg");
pred!(matches "software.daemon", "postgres");
pred!(metadata_exists "intent");
pred!(metadata_equals "intent", "ml-training");
pred!(and [a, b, c]);
pred!(or  [a, b, c]);
pred!(not a);

The string forms are <axis>.<key> literals; the macro splits them into (axis, key) via crate::adapter::net::behavior::tag::Tag::parse and panics at construction time on invalid axis prefixes — matching the substrate plan’s “validates shapes at parse time” contract for the macro.