Skip to main content

Module kernel

Module kernel 

Source
Expand description

The sans-I/O lifecycle kernel.

The kernel is a pure state machine: it decides the next Directive from its state and absorbs Notice reports a runtime feeds back. It performs no I/O and exposes no async fn, so it commits to no runtime shape. It encodes the lifecycle decision table only — it adds no orchestration behavior.

§Advanced surface

This is the advanced tier of Pacta’s public API: lower stability intent than the recommended surface (its API may evolve as the runtime story settles), though it stays a supported, governed core surface — not unsupported or slated for removal. Most consumers should compose with the Driver runtime (or the pacta facade) and never touch the kernel. Reach for it only to build a custom runtime; it is reached through pacta-contract directly, never through the pacta facade.

§Driving the kernel

A runtime drives one lifecycle step by looping: ask poll for the next Directive, perform it, report the outcome back with on_event, and repeat until result yields a terminal StepResult. The kernel decides what; the runtime performs it and injects time — the kernel reads no clock.

use pacta_contract::kernel::{Directive, Kernel, Notice, StepResult};
use pacta_contract::{Claim, Outcome, Pact, Retainer, Timestamp};

let mut kernel = Kernel::new();
let mut available = Some(Claim::new(
    Pact::new(Default::default(), "demo".into(), "demo".into(), Vec::new()),
    Retainer::new(Default::default()),
    Timestamp::from_millis(0),
));

let result = loop {
    if let Some(result) = kernel.result() {
        break result;
    }
    match kernel.poll() {
        Directive::Claim => kernel.on_event(Notice::Claimed(available.take())),
        Directive::Execute(_pact) => kernel.on_event(Notice::Executed(Outcome::Fulfilled)),
        Directive::Settle(_retainer, _outcome) => kernel.on_event(Notice::Settled),
        Directive::Idle => break StepResult::Idle,
        _ => unreachable!("driver handles every current kernel directive"),
    }
};

assert_eq!(result, StepResult::Settled(Outcome::Fulfilled));

Structs§

Kernel
The pure lifecycle state machine for a single step.

Enums§

Directive
An instruction the kernel issues for a runtime to perform.
Notice
A report a runtime feeds back after performing a Directive.
StepResult
The terminal result of one lifecycle step.