TL;DR: One line to add FAF project context to any Axum server. Feature-gated behind axum — zero impact when off. Your .faf is parsed once at startup, shared via Arc. Per-request cost: one atomic increment.

The One-Liner

use axum::{Router, routing::get};
use faf_rust_sdk::axum::{FafLayer, FafContext};

let app = Router::new()
    .route("/", get(handler))
    .layer(FafLayer::new());

async fn handler(faf: FafContext) -> String {
    format!("Project: {}", faf.project_name())
}

That's it. Every route in your app now has access to your project DNA.

No Feature Is the Feature

The Axum integration is behind a Cargo feature flag:

[features]
default = []
axum = ["dep:axum", "dep:tower", "dep:http"]

default = []. If you just want to parse .faf files, you get zero extra dependencies. The entire Axum module compiles out. This is how sqlx, reqwest, and tracing do it — the Rust ecosystem convention.

When you opt in:

faf-rust-sdk = { version = "1.3", features = ["axum"] }

You get FafContext, FafLayer, FafLayerBuilder — ~240 lines of code. Not because the problem is simple, but because the foundation is solid. The SDK already handles discovery, parsing, validation, and compression. The Axum layer is a thin Arc wrapper around what already works.

What You Get

TypeWhat
FafContextAxum extractor — delegates .project_name(), .score(), .data(), etc.
FafLayerTower Layer — injects context into every request via Extension
FafLayerBuilderBuilder with .dir(), .compression(), .validate()

FafLayer::new() discovers and parses your .faf at startup. If it's missing, the server panics immediately — fail at boot, not at request time. Use FafLayer::builder().try_build() for graceful error handling.

The Builder

For more control:

use faf_rust_sdk::axum::FafLayer;
use faf_rust_sdk::CompressionLevel;

let layer = FafLayer::builder()
    .dir("./my-project")
    .compression(CompressionLevel::Minimal)
    .try_build()?;

Pre-compute compressed context at startup. Serve minimal tokens per request. The builder pattern Rust devs expect.

Try It

cargo add faf-rust-sdk --features axum

GitHub

Source and release notes.

faf-rust-sdk

crates.io

Install the latest version.

faf-rust-sdk

The Numbers

  • v1.3.0 — Released March 7, 2026
  • 145/145 — Tests passing (+8 Axum integration)
  • ~240 lines — Entire middleware module
  • 1 Arc::clone — Per-request cost
  • 0 deps added — When feature is off