Just got axum up and running. Spent waaaay too long wrestling with rustic and rustfmt to get it to stop throwing errors, only to realize that the actual problem was my copy of rustfmt being waaaay out of date. With that fixed, the problem went away.

This commit is contained in:
Elf M. Sternberg 2026-05-10 08:33:42 -07:00
parent 47cae5dada
commit 841fa7e91e
4 changed files with 39 additions and 2 deletions

1
demo/rustfmt.toml Normal file
View File

@ -0,0 +1 @@
edition = "2021"

View File

@ -1,3 +1,37 @@
fn main() {
println!("Hello, world!");
use axum::{routing::get, Router};
use clap::Parser;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::path::PathBuf;
use tokio::net::TcpListener;
#[derive(Parser)]
struct Args {
#[arg(short, long)]
zip: Option<PathBuf>,
#[arg(short, long, default_value = "8001")]
port: u16,
}
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
let args = Args::parse();
// TODO: Add a test to see if `path`, if it exists, is a path to a folder or to a zip file. If a
// folder, opt for using serve_dir instead.
match &args.zip {
Some(path) => println!("Using external zip file: {}", path.display()),
None => {
println!("Using embedded zip file, if present. (TODO: Make this an error otherwise)")
}
}
let app = Router::new().route("/check", get(|| async { "OK" }));
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), args.port);
let listener = TcpListener::bind(addr)
.await
.expect("Failed to bind to port");
println!("Listening at {}", addr);
axum::serve(listener, app).await.unwrap();
}

1
rustfmt.toml Normal file
View File

@ -0,0 +1 @@
edition = "2021"

1
serve_zip/rustfmt.toml Normal file
View File

@ -0,0 +1 @@
edition = "2021"