Skip to main content

Crate engate_attach

Crate engate_attach 

Source
Expand description

engate-attach — typed attach lifecycle.

See engate-types for the philosophy + phase markers. This crate provides the runtime machinery: Producer / Consumer traits, the typestate-enforced Attach<P> value, the AttachBuilder, and the linear-ish History<S> handle.

§Quick example

use engate_attach::{Attach, Producer, Consumer};

let attach = Attach::builder()
    .producer(my_producer)
    .consumer(my_consumer)
    .build()                   // -> Attach<Spawned>
    .subscribe()?              // -> Attach<Subscribed>, also returns History<S>
    .replay(history)?          // -> Attach<Synced>
    .start_live();             // -> Attach<Live>

// Only an Attach<Live> can render.
attach.run();

§Why typestate over runtime FSM

A Result return + match on phase string would also work, but the compiler would let you write attach.replay() on a Subscribed that you forgot to subscribe() first. Typestate makes the malformed call a compile error: Spawned has no replay method; Subscribed has no start_live method. You CAN’T write the bug.

Structs§

Attach
The typed attach handle. P is the current phase; the available methods are gated on P so malformed call sequences are compile errors rather than runtime mismatches.
AttachConfig
Builder for the initial Attach<Spawned>. typed-builder enforces that both producer and consumer are set before .build() can be called.
History
A snapshot in flight from producer to consumer. #[must_use] + runtime drop-bomb together approximate linear typing: forgetting to consume History panics in debug builds, and clippy flags the dropped result in CI.

Traits§

Consumer
A consumer of producer items + snapshots. Mirrors the producer’s associated types so the type-checker enforces compatible pairs.
Producer
A producer of live data + bootable snapshots. The trait is the only thing engate needs to provide attach semantics; concrete producers (tear pane, WS channel, K8s log stream) implement it.

Type Aliases§

AttachSpawned
Type alias for clarity at call sites.