chore(lib): add dyn keyword to trait objects (#1820)
Requires Rust 1.27.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#![deny(warnings)]
|
||||
extern crate futures;
|
||||
extern crate hyper;
|
||||
|
||||
@@ -12,7 +13,7 @@ use hyper::{Body, Method, Request, Response, Server, StatusCode};
|
||||
///
|
||||
/// A boxed Future (trait object) is used as it is easier to understand
|
||||
/// and extend with more types. Advanced users could switch to `Either`.
|
||||
type BoxFut = Box<Future<Item = Response<Body>, Error = hyper::Error> + Send>;
|
||||
type BoxFut = Box<dyn Future<Item = Response<Body>, Error = hyper::Error> + Send>;
|
||||
|
||||
/// This is our service handler. It receives a Request, routes on its
|
||||
/// path, and returns a Future of a Response.
|
||||
|
||||
@@ -17,7 +17,7 @@ static MISSING: &[u8] = b"Missing field";
|
||||
static NOTNUMERIC: &[u8] = b"Number field is not numeric";
|
||||
|
||||
// Using service_fn, we can turn this function into a `Service`.
|
||||
fn param_example(req: Request<Body>) -> Box<Future<Item=Response<Body>, Error=hyper::Error> + Send> {
|
||||
fn param_example(req: Request<Body>) -> Box<dyn Future<Item=Response<Body>, Error=hyper::Error> + Send> {
|
||||
match (req.method(), req.uri().path()) {
|
||||
(&Method::GET, "/") | (&Method::GET, "/post") => {
|
||||
Box::new(future::ok(Response::new(INDEX.into())))
|
||||
|
||||
@@ -30,7 +30,7 @@ fn main() {
|
||||
hyper::rt::run(server);
|
||||
}
|
||||
|
||||
type ResponseFuture = Box<Future<Item=Response<Body>, Error=io::Error> + Send>;
|
||||
type ResponseFuture = Box<dyn Future<Item=Response<Body>, Error=io::Error> + Send>;
|
||||
|
||||
fn response_examples(req: Request<Body>) -> ResponseFuture {
|
||||
match (req.method(), req.uri().path()) {
|
||||
|
||||
@@ -16,7 +16,7 @@ static INDEX: &[u8] = b"<a href=\"test.html\">test.html</a>";
|
||||
static POST_DATA: &str = r#"{"original": "data"}"#;
|
||||
|
||||
type GenericError = Box<dyn std::error::Error + Send + Sync>;
|
||||
type ResponseFuture = Box<Future<Item=Response<Body>, Error=GenericError> + Send>;
|
||||
type ResponseFuture = Box<dyn Future<Item=Response<Body>, Error=GenericError> + Send>;
|
||||
|
||||
fn client_request_response(client: &Client<HttpConnector>) -> ResponseFuture {
|
||||
let req = Request::builder()
|
||||
|
||||
Reference in New Issue
Block a user