From 946226956fb6f7c5643d55379857a08c446b7b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Fri, 13 Sep 2024 17:58:38 +0200 Subject: [PATCH] feat: add axum example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- Cargo.toml | 1 + examples/axum/Cargo.toml | 10 ++++++++++ examples/axum/src/main.rs | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 examples/axum/Cargo.toml create mode 100644 examples/axum/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 54ceb3685..c7e9044df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ members = [ "benches/alloc", "benches/micro", "benches/netbench", + "examples/axum", "examples/demo", "examples/fuse_test", "examples/hello_world", diff --git a/examples/axum/Cargo.toml b/examples/axum/Cargo.toml new file mode 100644 index 000000000..ec175354f --- /dev/null +++ b/examples/axum/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "axum-example" +edition = "2021" + +[dependencies] +axum = "0.7" +tokio = "1" + +[target.'cfg(target_os = "hermit")'.dependencies] +hermit = { path = "../../hermit" } diff --git a/examples/axum/src/main.rs b/examples/axum/src/main.rs new file mode 100644 index 000000000..56932d1ed --- /dev/null +++ b/examples/axum/src/main.rs @@ -0,0 +1,19 @@ +use axum::routing::get; +use axum::Router; +#[cfg(target_os = "hermit")] +use hermit as _; +use tokio::{io, net}; + +#[tokio::main(flavor = "current_thread")] +async fn main() -> io::Result<()> { + let app = Router::new().route("/", get(root)); + + let listener = net::TcpListener::bind("0.0.0.0:9975").await?; + axum::serve(listener, app).await?; + + Ok(()) +} + +async fn root() -> &'static str { + "Hello, World!" +}