summaryrefslogtreecommitdiffstats
path: root/third_party/rust/warp/examples/returning.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/warp/examples/returning.rs')
-rw-r--r--third_party/rust/warp/examples/returning.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/third_party/rust/warp/examples/returning.rs b/third_party/rust/warp/examples/returning.rs
new file mode 100644
index 0000000000..f4f61e60fc
--- /dev/null
+++ b/third_party/rust/warp/examples/returning.rs
@@ -0,0 +1,20 @@
+use warp::{filters::BoxedFilter, Filter, Rejection, Reply};
+
+// Option 1: BoxedFilter
+// Note that this may be useful for shortening compile times when you are composing many filters.
+// Boxing the filters will use dynamic dispatch and speed up compilation while
+// making it slightly slower at runtime.
+pub fn assets_filter() -> BoxedFilter<(impl Reply,)> {
+ warp::path("assets").and(warp::fs::dir("./assets")).boxed()
+}
+
+// Option 2: impl Filter + Clone
+pub fn index_filter() -> impl Filter<Extract = (&'static str,), Error = Rejection> + Clone {
+ warp::path::end().map(|| "Index page")
+}
+
+#[tokio::main]
+async fn main() {
+ let routes = index_filter().or(assets_filter());
+ warp::serve(routes).run(([127, 0, 0, 1], 3030)).await;
+}