How to Serve Static Files in Rust

Web
Use the `warp` or `axum` crate to serve static files from a directory in Rust. Add the dependency to your `Cargo.toml`, then configure the router to serve the `static` folder.

How to Serve Static Files in Rust

Use the warp or axum crate to serve static files from a directory in Rust. Add the dependency to your Cargo.toml, then configure the router to serve the static folder.

use warp::Filter;

#[tokio::main]
async fn main() {
    let static_files = warp::fs::dir("static");
    warp::serve(static_files).run(([127, 0, 0, 1], 3030)).await;
}

Add warp = "0.3" and tokio = { version = "1", features = ["full"] } to your Cargo.toml dependencies.