Remove unneeded bounds on S in FromRequest(Parts) implementations

This doesn't actually allow using non-Send or non-Sync state types, but
it makes the docs simpler.
This commit is contained in:
Jonas Platte
2022-11-05 11:04:56 +01:00
parent da058db509
commit 05767b986e
39 changed files with 112 additions and 232 deletions
+2 -1
View File
@@ -84,8 +84,9 @@ pub trait FromRequestParts<S>: Sized {
/// #[async_trait]
/// impl<S, B> FromRequest<S, B> for MyExtractor
/// where
/// // these bounds are required by `async_trait`
/// // this bound is required by `async_trait`
/// B: Send + 'static,
/// // this bound is also required if the state parameter is not discarded with `_: &S`
/// S: Send + Sync,
/// {
/// type Rejection = http::StatusCode;
+8 -28
View File
@@ -9,7 +9,6 @@ use std::convert::Infallible;
impl<S, B> FromRequest<S, B> for Request<B>
where
B: Send,
S: Send + Sync,
{
type Rejection = Infallible;
@@ -19,10 +18,7 @@ where
}
#[async_trait]
impl<S> FromRequestParts<S> for Method
where
S: Send + Sync,
{
impl<S> FromRequestParts<S> for Method {
type Rejection = Infallible;
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
@@ -31,10 +27,7 @@ where
}
#[async_trait]
impl<S> FromRequestParts<S> for Uri
where
S: Send + Sync,
{
impl<S> FromRequestParts<S> for Uri {
type Rejection = Infallible;
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
@@ -43,10 +36,7 @@ where
}
#[async_trait]
impl<S> FromRequestParts<S> for Version
where
S: Send + Sync,
{
impl<S> FromRequestParts<S> for Version {
type Rejection = Infallible;
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
@@ -60,10 +50,7 @@ where
///
/// [`TypedHeader`]: https://docs.rs/axum/latest/axum/extract/struct.TypedHeader.html
#[async_trait]
impl<S> FromRequestParts<S> for HeaderMap
where
S: Send + Sync,
{
impl<S> FromRequestParts<S> for HeaderMap {
type Rejection = Infallible;
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
@@ -77,7 +64,6 @@ where
B: http_body::Body + Send + 'static,
B::Data: Send,
B::Error: Into<BoxError>,
S: Send + Sync,
{
type Rejection = BytesRejection;
@@ -101,18 +87,13 @@ where
B: http_body::Body + Send + 'static,
B::Data: Send,
B::Error: Into<BoxError>,
S: Send + Sync,
{
type Rejection = StringRejection;
async fn from_request(req: Request<B>, state: &S) -> Result<Self, Self::Rejection> {
let bytes = Bytes::from_request(req, state)
.await
.map_err(|err| match err {
BytesRejection::FailedToBufferBody(inner) => {
StringRejection::FailedToBufferBody(inner)
}
})?;
async fn from_request(req: Request<B>, _: &S) -> Result<Self, Self::Rejection> {
let bytes: Bytes = req.extract().await.map_err(|err| match err {
BytesRejection::FailedToBufferBody(inner) => StringRejection::FailedToBufferBody(inner),
})?;
let string = std::str::from_utf8(&bytes)
.map_err(InvalidUtf8::from_err)?
@@ -126,7 +107,6 @@ where
impl<S, B> FromRequest<S, B> for Parts
where
B: Send + 'static,
S: Send + Sync,
{
type Rejection = Infallible;
+1 -4
View File
@@ -5,10 +5,7 @@ use http::request::{Parts, Request};
use std::convert::Infallible;
#[async_trait]
impl<S> FromRequestParts<S> for ()
where
S: Send + Sync,
{
impl<S> FromRequestParts<S> for () {
type Rejection = Infallible;
async fn from_request_parts(_: &mut Parts, _: &S) -> Result<(), Self::Rejection> {