mirror of https://github.com/rwf2/Rocket.git
Use the 'response::Result' alias in all 'Responder' impls.
This commit is contained in:
parent
c31ad28efc
commit
92ce006e2c
|
@ -184,13 +184,13 @@ pub trait Responder<'r> {
|
||||||
/// returned, the error catcher for the given status is retrieved and called
|
/// 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
|
/// to generate a final error response, which is then written out to the
|
||||||
/// client.
|
/// client.
|
||||||
fn respond_to(self, request: &Request) -> Result<Response<'r>, Status>;
|
fn respond_to(self, request: &Request) -> response::Result<'r>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a response with Content-Type `text/plain` and a fixed-size body
|
/// Returns a response with Content-Type `text/plain` and a fixed-size body
|
||||||
/// containing the string `self`. Always returns `Ok`.
|
/// containing the string `self`. Always returns `Ok`.
|
||||||
impl<'r> Responder<'r> for &'r str {
|
impl<'r> Responder<'r> for &'r str {
|
||||||
fn respond_to(self, _: &Request) -> Result<Response<'r>, Status> {
|
fn respond_to(self, _: &Request) -> response::Result<'r> {
|
||||||
Response::build()
|
Response::build()
|
||||||
.header(ContentType::Plain)
|
.header(ContentType::Plain)
|
||||||
.sized_body(Cursor::new(self))
|
.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
|
/// Returns a response with Content-Type `text/plain` and a fixed-size body
|
||||||
/// containing the string `self`. Always returns `Ok`.
|
/// containing the string `self`. Always returns `Ok`.
|
||||||
impl<'r> Responder<'r> for String {
|
impl<'r> Responder<'r> for String {
|
||||||
fn respond_to(self, _: &Request) -> Result<Response<'r>, Status> {
|
fn respond_to(self, _: &Request) -> response::Result<'r> {
|
||||||
Response::build()
|
Response::build()
|
||||||
.header(ContentType::Plain)
|
.header(ContentType::Plain)
|
||||||
.sized_body(Cursor::new(self))
|
.sized_body(Cursor::new(self))
|
||||||
|
@ -222,14 +222,14 @@ impl<'r> Responder<'r> for Vec<u8> {
|
||||||
|
|
||||||
/// Returns a response with a sized body for the file. Always returns `Ok`.
|
/// Returns a response with a sized body for the file. Always returns `Ok`.
|
||||||
impl<'r> Responder<'r> for File {
|
impl<'r> Responder<'r> for File {
|
||||||
fn respond_to(self, _: &Request) -> Result<Response<'r>, Status> {
|
fn respond_to(self, _: &Request) -> response::Result<'r> {
|
||||||
Response::build().streamed_body(BufReader::new(self)).ok()
|
Response::build().streamed_body(BufReader::new(self)).ok()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an empty, default `Response`. Always returns `Ok`.
|
/// Returns an empty, default `Response`. Always returns `Ok`.
|
||||||
impl<'r> Responder<'r> for () {
|
impl<'r> Responder<'r> for () {
|
||||||
fn respond_to(self, _: &Request) -> Result<Response<'r>, Status> {
|
fn respond_to(self, _: &Request) -> response::Result<'r> {
|
||||||
Ok(Response::new())
|
Ok(Response::new())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,7 +237,7 @@ impl<'r> Responder<'r> for () {
|
||||||
/// If `self` is `Some`, responds with the wrapped `Responder`. Otherwise prints
|
/// If `self` is `Some`, responds with the wrapped `Responder`. Otherwise prints
|
||||||
/// a warning message and returns an `Err` of `Status::NotFound`.
|
/// a warning message and returns an `Err` of `Status::NotFound`.
|
||||||
impl<'r, R: Responder<'r>> Responder<'r> for Option<R> {
|
impl<'r, R: Responder<'r>> Responder<'r> for Option<R> {
|
||||||
fn respond_to(self, req: &Request) -> Result<Response<'r>, Status> {
|
fn respond_to(self, req: &Request) -> response::Result<'r> {
|
||||||
self.map_or_else(|| {
|
self.map_or_else(|| {
|
||||||
warn_!("Response was `None`.");
|
warn_!("Response was `None`.");
|
||||||
Err(Status::NotFound)
|
Err(Status::NotFound)
|
||||||
|
@ -249,7 +249,7 @@ impl<'r, R: Responder<'r>> Responder<'r> for Option<R> {
|
||||||
/// an error message with the `Err` value returns an `Err` of
|
/// an error message with the `Err` value returns an `Err` of
|
||||||
/// `Status::InternalServerError`.
|
/// `Status::InternalServerError`.
|
||||||
impl<'r, R: Responder<'r>, E: fmt::Debug> Responder<'r> for Result<R, E> {
|
impl<'r, R: Responder<'r>, E: fmt::Debug> Responder<'r> for Result<R, E> {
|
||||||
default fn respond_to(self, req: &Request) -> Result<Response<'r>, Status> {
|
default fn respond_to(self, req: &Request) -> response::Result<'r> {
|
||||||
self.map(|r| r.respond_to(req)).unwrap_or_else(|e| {
|
self.map(|r| r.respond_to(req)).unwrap_or_else(|e| {
|
||||||
error_!("Response was `Err`: {:?}.", e);
|
error_!("Response was `Err`: {:?}.", e);
|
||||||
Err(Status::InternalServerError)
|
Err(Status::InternalServerError)
|
||||||
|
@ -260,7 +260,7 @@ impl<'r, R: Responder<'r>, E: fmt::Debug> Responder<'r> for Result<R, E> {
|
||||||
/// Responds with the wrapped `Responder` in `self`, whether it is `Ok` or
|
/// Responds with the wrapped `Responder` in `self`, whether it is `Ok` or
|
||||||
/// `Err`.
|
/// `Err`.
|
||||||
impl<'r, R: Responder<'r>, E: Responder<'r> + fmt::Debug> Responder<'r> for Result<R, E> {
|
impl<'r, R: Responder<'r>, E: Responder<'r> + fmt::Debug> Responder<'r> for Result<R, E> {
|
||||||
fn respond_to(self, req: &Request) -> Result<Response<'r>, Status> {
|
fn respond_to(self, req: &Request) -> response::Result<'r> {
|
||||||
match self {
|
match self {
|
||||||
Ok(responder) => responder.respond_to(req),
|
Ok(responder) => responder.respond_to(req),
|
||||||
Err(responder) => responder.respond_to(req),
|
Err(responder) => responder.respond_to(req),
|
||||||
|
|
Loading…
Reference in New Issue