use std::{convert::Infallible, future::Future};
use super::RequestParts;
use crate::IntoResponse;
pub trait FromRequestParts: Send + Sized {
type Rejection: IntoResponse;
fn from_request_parts(
parts: &mut RequestParts,
) -> impl Future<Output = Result<Self, Self::Rejection>> + Send;
}
impl FromRequestParts for http::Method {
type Rejection = Infallible;
async fn from_request_parts(parts: &mut RequestParts) -> Result<Self, Self::Rejection> {
Ok(parts.method.clone())
}
}
impl FromRequestParts for http::Uri {
type Rejection = Infallible;
async fn from_request_parts(parts: &mut RequestParts) -> Result<Self, Self::Rejection> {
Ok(parts.uri.clone())
}
}
impl<T> FromRequestParts for Result<T, T::Rejection>
where
T: FromRequestParts,
T::Rejection: Send,
{
type Rejection = Infallible;
async fn from_request_parts(parts: &mut RequestParts) -> Result<Self, Self::Rejection> {
Ok(T::from_request_parts(parts).await)
}
}