pub type Outcome<'r> = Outcome<Response<'r>, Status, (Data<'r>, Status)>;
Expand description
Type alias for the return type of a Route
’s
Handler::handle()
.
Aliased Type§
enum Outcome<'r> {
Success(Response<'r>),
Error(Status),
Forward((Data<'r>, Status)),
}
Variants§
Success(Response<'r>)
Contains the success value.
Error(Status)
Contains the error error value.
Forward((Data<'r>, Status))
Contains the value to forward on.
Implementations§
source§impl<'r, 'o: 'r> Outcome<'o>
impl<'r, 'o: 'r> Outcome<'o>
sourcepub fn from<R: Responder<'r, 'o>>(
req: &'r Request<'_>,
responder: R,
) -> Outcome<'r>
pub fn from<R: Responder<'r, 'o>>( req: &'r Request<'_>, responder: R, ) -> Outcome<'r>
Return the Outcome
of response to req
from responder
.
If the responder returns Ok
, an outcome of Success
is returned with
the response. If the responder returns Err
, an outcome of Error
is
returned with the status code.
§Example
use rocket::{Request, Data, route};
fn str_responder<'r>(req: &'r Request, _: Data<'r>) -> route::Outcome<'r> {
route::Outcome::from(req, "Hello, world!")
}
sourcepub fn try_from<R, E>(req: &'r Request<'_>, result: Result<R, E>) -> Outcome<'r>
pub fn try_from<R, E>(req: &'r Request<'_>, result: Result<R, E>) -> Outcome<'r>
Return the Outcome
of response to req
from responder
.
If the responder returns Ok
, an outcome of Success
is returned with
the response. If the responder returns Err
, an outcome of Error
is
returned with the status code.
§Example
use rocket::{Request, Data, route};
fn str_responder<'r>(req: &'r Request, _: Data<'r>) -> route::Outcome<'r> {
route::Outcome::from(req, "Hello, world!")
}
sourcepub fn error(code: Status) -> Outcome<'r>
pub fn error(code: Status) -> Outcome<'r>
Return an Outcome
of Error
with the status code code
. This is
equivalent to Outcome::Error(code)
.
This method exists to be used during manual routing.
§Example
use rocket::{Request, Data, route};
use rocket::http::Status;
fn bad_req_route<'r>(_: &'r Request, _: Data<'r>) -> route::Outcome<'r> {
route::Outcome::error(Status::BadRequest)
}
sourcepub fn forward(data: Data<'r>, status: Status) -> Outcome<'r>
pub fn forward(data: Data<'r>, status: Status) -> Outcome<'r>
Return an Outcome
of Forward
with the data data
and status
status
. This is equivalent to Outcome::Forward((data, status))
.
This method exists to be used during manual routing.
§Example
use rocket::{Request, Data, route};
use rocket::http::Status;
fn always_forward<'r>(_: &'r Request, data: Data<'r>) -> route::Outcome<'r> {
route::Outcome::forward(data, Status::InternalServerError)
}