1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#![deny(warnings)]
use warp::{http::StatusCode, Filter};
async fn dyn_reply(word: String) -> Result<Box<dyn warp::Reply>, warp::Rejection> {
if &word == "hello" {
Ok(Box::new("world"))
} else {
Ok(Box::new(StatusCode::BAD_REQUEST))
}
}
#[tokio::main]
async fn main() {
let routes = warp::path::param().and_then(dyn_reply);
warp::serve(routes).run(([127, 0, 0, 1], 3030)).await;
}