From 92ce006e2cbb6f25319eb2ae4d4269b2e2ae422f Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Thu, 21 Sep 2017 18:49:28 -0700 Subject: [PATCH] Use the 'response::Result' alias in all 'Responder' impls. --- lib/src/response/responder.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/src/response/responder.rs b/lib/src/response/responder.rs index 9339695a..362269d7 100644 --- a/lib/src/response/responder.rs +++ b/lib/src/response/responder.rs @@ -184,13 +184,13 @@ pub trait Responder<'r> { /// returned, the error catcher for the given status is retrieved and called /// to generate a final error response, which is then written out to the /// client. - fn respond_to(self, request: &Request) -> Result, Status>; + fn respond_to(self, request: &Request) -> response::Result<'r>; } /// Returns a response with Content-Type `text/plain` and a fixed-size body /// containing the string `self`. Always returns `Ok`. impl<'r> Responder<'r> for &'r str { - fn respond_to(self, _: &Request) -> Result, Status> { + fn respond_to(self, _: &Request) -> response::Result<'r> { Response::build() .header(ContentType::Plain) .sized_body(Cursor::new(self)) @@ -201,7 +201,7 @@ impl<'r> Responder<'r> for &'r str { /// Returns a response with Content-Type `text/plain` and a fixed-size body /// containing the string `self`. Always returns `Ok`. impl<'r> Responder<'r> for String { - fn respond_to(self, _: &Request) -> Result, Status> { + fn respond_to(self, _: &Request) -> response::Result<'r> { Response::build() .header(ContentType::Plain) .sized_body(Cursor::new(self)) @@ -222,14 +222,14 @@ impl<'r> Responder<'r> for Vec { /// Returns a response with a sized body for the file. Always returns `Ok`. impl<'r> Responder<'r> for File { - fn respond_to(self, _: &Request) -> Result, Status> { + fn respond_to(self, _: &Request) -> response::Result<'r> { Response::build().streamed_body(BufReader::new(self)).ok() } } /// Returns an empty, default `Response`. Always returns `Ok`. impl<'r> Responder<'r> for () { - fn respond_to(self, _: &Request) -> Result, Status> { + fn respond_to(self, _: &Request) -> response::Result<'r> { Ok(Response::new()) } } @@ -237,7 +237,7 @@ impl<'r> Responder<'r> for () { /// If `self` is `Some`, responds with the wrapped `Responder`. Otherwise prints /// a warning message and returns an `Err` of `Status::NotFound`. impl<'r, R: Responder<'r>> Responder<'r> for Option { - fn respond_to(self, req: &Request) -> Result, Status> { + fn respond_to(self, req: &Request) -> response::Result<'r> { self.map_or_else(|| { warn_!("Response was `None`."); Err(Status::NotFound) @@ -249,7 +249,7 @@ impl<'r, R: Responder<'r>> Responder<'r> for Option { /// an error message with the `Err` value returns an `Err` of /// `Status::InternalServerError`. impl<'r, R: Responder<'r>, E: fmt::Debug> Responder<'r> for Result { - default fn respond_to(self, req: &Request) -> Result, Status> { + default fn respond_to(self, req: &Request) -> response::Result<'r> { self.map(|r| r.respond_to(req)).unwrap_or_else(|e| { error_!("Response was `Err`: {:?}.", e); Err(Status::InternalServerError) @@ -260,7 +260,7 @@ impl<'r, R: Responder<'r>, E: fmt::Debug> Responder<'r> for Result { /// Responds with the wrapped `Responder` in `self`, whether it is `Ok` or /// `Err`. impl<'r, R: Responder<'r>, E: Responder<'r> + fmt::Debug> Responder<'r> for Result { - fn respond_to(self, req: &Request) -> Result, Status> { + fn respond_to(self, req: &Request) -> response::Result<'r> { match self { Ok(responder) => responder.respond_to(req), Err(responder) => responder.respond_to(req),