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!" +}