Debian Codegraph @

third_party/rust/warp/examples/returning.rs

raw
1 use warp::{filters::BoxedFilter, Filter, Rejection, Reply};
2
3 // Option 1: BoxedFilter
4 // Note that this may be useful for shortening compile times when you are composing many filters.
5 // Boxing the filters will use dynamic dispatch and speed up compilation while
6 // making it slightly slower at runtime.
7 pub fn assets_filter() -> BoxedFilter<(impl Reply,)> {
8 warp::path("assets").and(warp::fs::dir("./assets")).boxed()
9 }
10
11 // Option 2: impl Filter + Clone
12 pub fn index_filter() -> impl Filter<Extract = (&'static str,), Error = Rejection> + Clone {
13 warp::path::end().map(|| "Index page")
14 }
15
16 #[tokio::main]
17 async fn main() {
18 let routes = index_filter().or(assets_filter());
19 warp::serve(routes).run(([127, 0, 0, 1], 3030)).await;
20 }