pneumatic (1.0.0)

Published 2026-09-19 06:07:50 +00:00 by decduck

Installation

[registries.forgejo]
index = "sparse+" # Sparse index
# index = "" # Git

[net]
git-fetch-with-cli = true
cargo add pneumatic@1.0.0 --registry forgejo

About this package

pneumatic

pneumatic provides static delegation from an enum to the single-field tuple variants it wraps.

use std::future::Future;
use pneumatic::{pneumatic_trait, Pneumatic};

#[pneumatic_trait]
trait Operation {
    fn name(&self) -> String;
    fn run(&self) -> impl Future<Output = String>;
}

#[derive(Pneumatic)]
#[pneumatic(Operation)]
enum Operations {
    First(First),
    Second(Second),
}

The trait attribute records method signatures in a hidden callback macro. The enum derive consumes that method list and creates a match over every variant. Methods returning impl Future<Output = T> become async fn methods returning T; each variant call is awaited inside its match arm.

The enum must use one-field tuple variants, and delegated methods must have a receiver with identifier-pattern arguments. Generic methods are not currently supported. Rust does not allow derive macros on traits, so traits use the pneumatic_trait attribute.

Run the example test with:

cargo test

Dependencies

ID Version
proc-macro2 ^1
quote ^1
syn ^2
futures ^0.3
Details
Cargo
2026-09-19 06:07:50 +00:00
2
7.9 KiB
Assets (1)
Versions (2) View all
1.1.0 2026-09-19
1.0.0 2026-09-19