fnroute 0.1.0

A small function router with axum-style handler extraction.
Documentation
  • Coverage
  • 0%
    0 out of 19 items documented0 out of 0 items with examples
  • Size
  • Source code size: 23.82 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 974.16 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • atlas-orien

fnroute

fnroute is a small function router with axum-style handler extraction.

It is not an HTTP framework. It is a general-purpose route dispatcher that can register async and sync functions with different parameter lists, then extract those parameters from a route context.

fnroute is zero-dependency and supports no_std with alloc.

use fnroute::{Input, Param, RouteContext, Router, State};

#[derive(Clone)]
struct AppState {
    name: String,
}

#[derive(Clone)]
struct Payload {
    action: String,
}

async fn user(
    Param(id): Param<u64>,
    Input(payload): Input<Payload>,
    State(state): State<AppState>,
) -> String {
    format!("{} user {id} {}", state.name, payload.action)
}

# async fn example() {
let app = Router::<String>::new()
    .with_state(AppState {
        name: "demo".to_string(),
    })
    .route("users/:id", user);

let output = app
    .call_with(RouteContext::new("users/42").input(Payload {
        action: "saved".to_string(),
    }))
    .await
    .unwrap();

assert_eq!(output, "demo user 42 saved");
# }

Core Idea

  • Router<R, S> stores routes and fixes the final return type R.
  • FromRoute<S> lets each parameter type extract itself from RouteContext.
  • route(...) registers async handlers.
  • route_sync(...) registers sync handlers.

Handler implementations are generated up to 16 parameters.