title: Grounded Wrapper category: concepts

Grounded<T> — Compile-Time Ground-State Guarantee

The uor_foundation::enforcement::Grounded<T: GroundedShape> wrapper carries the compile-time witness that op:GS_4 holds for the value it wraps:

A Grounded<T> can only be produced by the reduction pipeline (or by uor_ground! macro expansion) — never by hand. The wrapper's private fields and sealed GroundedShape supertrait guarantee this at the type-system level.

What's inside

pub struct Grounded<T: GroundedShape> {
    validated: Validated<GroundingCertificate>,
    bindings: BindingsTable,
    witt_level_bits: u16,
    unit_address: u128,
    _phantom: PhantomData<T>,
}

How to produce one

The uor_ground! macro is the consumer-facing entry point:

use uor_foundation::enforcement::prelude::*;
use uor_foundation_macros::{uor_ground, ConstrainedType};

#[derive(ConstrainedType, Default)]
#[uor(residue = 255, hamming = 8)]
struct Pixel;

let unit: Grounded<Pixel> = uor_ground! {
    compile_unit hello_pixel {
        root_term: { 0 };
        witt_level_ceiling: W8;
        thermodynamic_budget: 64.0;
        target_domains: { ComposedAlgebraic };
    } as Grounded<Pixel>
};

The trailing as Grounded<Pixel> clause is required so the macro can recover the type parameter T at expansion time. The macro body runs the v0.2.1 reduction pipeline in-process, applies all 6 preflight checks and 7 reduction stages, and produces the Grounded<Pixel> value via the sealed back-door minting API.

Sealed-constructor discipline

The GroundedShape supertrait is sealed through __macro_internals::GroundedShapeSealed. The only way to implement it is via #[derive(ConstrainedType)], which emits the impl through the doc-hidden back-door module. Any other impl attempt fails with a private-path error at compile time.

The cargo-uor CLI's uor::unsealed_grounded lint (future release) will additionally flag any direct call to the __uor_macro_mint_grounded back-door function outside uor-foundation-macros-generated code.

See also