Skip to main content

Module template

Module template 

Source
Expand description

Owning, source-free recipes for composition in one native Sheet.

Parameters alias caller-owned cells; private declarations allocate fresh cells in declaration order. Factories run at instantiation, never propagation. Each factory must create fresh execution state and satisfy Method’s contract.

use adam_rs::{Method, MethodRecipe, Sheet, TemplateBuilder};

let mut builder = TemplateBuilder::new();
let input = builder.parameter::<i32>("input")?;
let output = builder.parameter::<i32>("output")?;
let method = MethodRecipe::new(&[input], &[output], |ins, outs| {
    Ok(Method::from_fn_1_1(ins[0], outs[0], |x: &i32| Ok(*x)))
})?;
builder.relationship(vec![method])?;
let template = builder.finish()?;
let mut sheet = Sheet::new();
let input = sheet.add_source(7i32);
let output = sheet.add_cell(0i32);
let instance = template.instantiate(&mut sheet, &[("output", output), ("input", input)])?;
sheet.propagate()?;
assert_eq!(*sheet.read::<i32>(output)?, 7);
assert_eq!(instance.cells(), &[input, output]);

This path constructs native methods directly: it needs no CEL text, lexer, parser or operation lookup. For checked multiplication with a source-bound factor, run cargo run -p adam-lang --example templates in the workspace. That example’s native path uses only this crate’s recipe and sheet APIs.

Named actuals must cover each parameter once, use distinct live cells from the destination sheet, and match the declared concrete types. Fixed sources specialize away every method that would write them. An empty specialized relationship fails before factories run. out cells cannot be actuals. Parameters keep caller-owned filters, requirements, strength and aspirations; component-owned policies may govern only private cells.

Finished templates own their factories; each factory creates fresh execution state. Immutable captures may be shared. Live methods survive dropping both the template and its returned instance metadata. Instantiation runs factories but never propagates. On error, the destination remains safely discardable; instantiation does not promise rollback. TemplateError::Construction retains the actual native site and original cause without invented source spans. Conditional inclusion requires a transitively relationship-only component. Private state remains available to unconditional inclusions.

Structs§

CellSlot
Identifies a cell declaration within exactly one owning builder/template.
Instance
Owns an opaque instance identity and its mapped live handles.
InstanceOccurrence
Retains one occurrence’s identity, immediate parent, and local mapping ranges.
MethodOrigin
Maps one compact live method index back to its authored declaration.
MethodRecipe
Stores declared local edges and a repeatable, owning native method factory.
OccurrenceId
Identifies one inclusion occurrence within exactly one live expansion.
RelationshipSlot
Identifies a relationship declaration or inclusion group within one owning recipe.
SheetTemplate
Owns an immutable ordered graph recipe, independent of any live sheet.
TemplateBuilder
Owns declarations and validates all local references before accepting them.
TemplateId
Identifies an immutable recipe without retaining its factories or inclusion edges.
TemplateInclusion
Returns one owner-checked relationship-group handle in the including namespace.

Enums§

ConstructionSite
Identifies an authored construction boundary before any live relationship exists.
TemplateError
Identifies a malformed recipe, binding, factory, or native graph construction.

Functions§

check_relationship_edges
Checks ordinary relationship edge structure without constructing methods or a live sheet.