smol-axum

Crates.iosmol-axum
lib.rssmol-axum
version0.1.0
sourcesrc
created_at2023-12-29 21:14:53.334055
updated_at2023-12-29 21:14:53.334055
descriptionIntegrations between `smol` and `axum`
homepagehttps://codeberg.org/notgull/smol-axum
repositoryhttps://codeberg.org/notgull/smol-axum
max_upload_size
id1083644
size47,563
admins (github:smol-rs:admins)

documentation

README

smol-axum

Integrations between smol and axum.

By default, axum only supports the tokio runtime. This crate adds a serve function that can be used with smol's networking types.

Examples

use async_io::Async;
use axum::{response::Html, routing::get, Router};
use macro_rules_attribute::apply;

use std::io;
use std::net::TcpListener;
use std::sync::Arc;

#[apply(smol_macros::main!)]
async fn main(ex: &Arc<smol_macros::Executor<'_>>) -> io::Result<()> {
    // Build our application with a route.
    let app = Router::new().route("/", get(handler));

    // Create a `smol`-based TCP listener.
    let listener = Async::<TcpListener>::bind(([127, 0, 0, 1], 3000)).unwrap();
    println!("listening on {}", listener.get_ref().local_addr().unwrap());

    // Run it using `smol_axum`
    smol_axum::serve(ex.clone(), listener, app).await
}

async fn handler() -> Html<&'static str> {
    Html("<h1>Hello, World!</h1>")
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 0

cargo fmt