Closed rongzhongyang closed 3 weeks ago
use salvo::prelude::*; use salvo::serve_static::StaticDir; //这行报错。没有serve_static
async fn main() { tracing_subscriber::fmt().init();
let router = Router::with_path("<**path>").get( StaticDir::new([ "examples/static-dir-list/static/boy", "examples/static-dir-list/static/girl", ]) .defaults("index.html") .auto_list(true), ); let acceptor = TcpListener::new("127.0.0.1:5800").bind().await; Server::new(acceptor).serve(router).await;
}
看这里,你需要打开对应的 feature 的。 https://github.com/salvo-rs/salvo/blob/main/examples/static-dir-list/Cargo.toml
salvo = { workspace = true, features=["serve-static"] }
use salvo::prelude::*; use salvo::serve_static::StaticDir; //这行报错。没有serve_static
[tokio::main]
async fn main() { tracing_subscriber::fmt().init();
}