mirror of https://github.com/rwf2/Rocket.git
Simplify FromRequestAsync trait definition.
This commit is contained in:
parent
003bf77c29
commit
468f4d9314
|
@ -144,7 +144,7 @@ pub fn database_attr(attr: TokenStream, input: TokenStream) -> Result<TokenStrea
|
|||
impl<'a, 'r> #request::FromRequestAsync<'a, 'r> for #guard_type {
|
||||
type Error = ();
|
||||
|
||||
fn from_request<'fut>(request: &'a #request::Request<'r>) -> #request::FromRequestFuture<'fut, Self, Self::Error> where 'a: 'fut {
|
||||
fn from_request(request: &'a #request::Request<'r>) -> #request::FromRequestFuture<'a, Self, Self::Error> {
|
||||
use ::rocket::{Outcome, http::Status};
|
||||
Box::pin(async move {
|
||||
let pool = ::rocket::try_outcome!(request.guard::<::rocket::State<'_, #pool_type>>()).0.clone();
|
||||
|
|
|
@ -47,7 +47,7 @@ pub trait FromRequestAsync<'a, 'r>: Sized {
|
|||
/// the derivation fails in an unrecoverable fashion, `Failure` is returned.
|
||||
/// `Forward` is returned to indicate that the request should be forwarded
|
||||
/// to other matching routes, if any.
|
||||
fn from_request<'fut>(request: &'a Request<'r>) -> FromRequestFuture<'fut, Self, Self::Error> where 'a: 'fut;
|
||||
fn from_request(request: &'a Request<'r>) -> FromRequestFuture<'a, Self, Self::Error>;
|
||||
}
|
||||
|
||||
/// Trait implemented by request guards to derive a value from incoming
|
||||
|
@ -377,7 +377,7 @@ pub trait FromRequest<'a, 'r>: Sized {
|
|||
impl<'a, 'r, T: FromRequest<'a, 'r>> FromRequestAsync<'a, 'r> for T {
|
||||
type Error = T::Error;
|
||||
|
||||
fn from_request<'fut>(request: &'a Request<'r>) -> BoxFuture<'fut, Outcome<Self, Self::Error>> where 'a: 'fut {
|
||||
fn from_request(request: &'a Request<'r>) -> BoxFuture<'a, Outcome<Self, Self::Error>> {
|
||||
Box::pin(async move { T::from_request(request) })
|
||||
}
|
||||
}
|
||||
|
@ -453,7 +453,7 @@ impl FromRequest<'_, '_> for SocketAddr {
|
|||
impl<'a, 'r, T: FromRequestAsync<'a, 'r> + 'a> FromRequestAsync<'a, 'r> for Result<T, T::Error> {
|
||||
type Error = std::convert::Infallible;
|
||||
|
||||
fn from_request<'fut>(request: &'a Request<'r>) -> BoxFuture<'fut, Outcome<Self, Self::Error>> where 'a: 'fut {
|
||||
fn from_request(request: &'a Request<'r>) -> BoxFuture<'a, Outcome<Self, Self::Error>> {
|
||||
// TODO: FutureExt::map is a workaround (see rust-lang/rust#60658)
|
||||
use futures_util::future::FutureExt;
|
||||
T::from_request(request).map(|x| match x {
|
||||
|
@ -467,7 +467,7 @@ impl<'a, 'r, T: FromRequestAsync<'a, 'r> + 'a> FromRequestAsync<'a, 'r> for Resu
|
|||
impl<'a, 'r, T: FromRequestAsync<'a, 'r> + 'a> FromRequestAsync<'a, 'r> for Option<T> {
|
||||
type Error = std::convert::Infallible;
|
||||
|
||||
fn from_request<'fut>(request: &'a Request<'r>) -> BoxFuture<'fut, Outcome<Self, Self::Error>> where 'a: 'fut {
|
||||
fn from_request(request: &'a Request<'r>) -> BoxFuture<'a, Outcome<Self, Self::Error>> {
|
||||
// TODO: FutureExt::map is a workaround (see rust-lang/rust#60658)
|
||||
use futures_util::future::FutureExt;
|
||||
T::from_request(request).map(|x| match x {
|
||||
|
|
|
@ -44,8 +44,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for Guard2 {
|
|||
impl<'a, 'r> FromRequestAsync<'a, 'r> for Guard3 {
|
||||
type Error = ();
|
||||
|
||||
fn from_request<'fut>(req: &'a Request<'r>) -> FromRequestFuture<'fut, Self, ()>
|
||||
where 'a: 'fut
|
||||
fn from_request(req: &'a Request<'r>) -> FromRequestFuture<'a, Self, ()>
|
||||
{
|
||||
Box::pin(async move {
|
||||
let atomics = try_outcome!(req.guard::<State<'_, Atomics>>());
|
||||
|
@ -62,8 +61,7 @@ impl<'a, 'r> FromRequestAsync<'a, 'r> for Guard3 {
|
|||
impl<'a, 'r> FromRequestAsync<'a, 'r> for Guard4 {
|
||||
type Error = ();
|
||||
|
||||
fn from_request<'fut>(req: &'a Request<'r>) -> FromRequestFuture<'fut, Self, ()>
|
||||
where 'a: 'fut
|
||||
fn from_request(req: &'a Request<'r>) -> FromRequestFuture<'a, Self, ()>
|
||||
{
|
||||
Box::pin(async move {
|
||||
try_outcome!(Guard3::from_request(req).await);
|
||||
|
|
Loading…
Reference in New Issue