Created
September 30, 2019 00:18
-
-
Save udoprog/8a8ae0d188612ef29754f92e3959b35d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use futures::Future; | |
use warp::Filter; | |
#[tokio::main] | |
async fn main() { | |
let r1 = warp::path("index").and_then(route1); | |
let r2 = warp::path::param().and_then(route2); | |
let routes = r1.recover(recover).or(r2.recover(recover)); | |
warp::serve(routes).run(([127, 0, 0, 1], 3020)).await; | |
} | |
fn route1() -> impl Future<Output = Result<impl warp::Reply, warp::Rejection>> { | |
dbg!("was here"); | |
futures::future::err::<String, warp::Rejection>(warp::reject::custom( | |
std::io::Error::from(std::io::ErrorKind::ConnectionAborted), | |
)) | |
} | |
fn route2(_param: String) -> impl Future<Output = Result<impl warp::Reply, warp::Rejection>> { | |
futures::future::ok("hello world") | |
} | |
async fn recover(err: warp::Rejection) -> Result<impl warp::Reply, warp::Rejection> { | |
Ok(warp::reply::with_status("an error happened", warp::http::StatusCode::BAD_REQUEST)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment