mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-29 00:00:18 +02:00
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:
@@ -141,15 +141,12 @@ mod tests {
|
||||
struct Extractor(Instant);
|
||||
|
||||
#[async_trait]
|
||||
impl<S> FromRequestParts<S> for Extractor
|
||||
where
|
||||
S: Send + Sync,
|
||||
{
|
||||
impl<S> FromRequestParts<S> for Extractor {
|
||||
type Rejection = Infallible;
|
||||
|
||||
async fn from_request_parts(
|
||||
_parts: &mut Parts,
|
||||
_state: &S,
|
||||
_: &S,
|
||||
) -> Result<Self, Self::Rejection> {
|
||||
COUNTER.fetch_add(1, Ordering::SeqCst);
|
||||
Ok(Self(Instant::now()))
|
||||
|
||||
@@ -89,13 +89,10 @@ pub struct CookieJar {
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<S> FromRequestParts<S> for CookieJar
|
||||
where
|
||||
S: Send + Sync,
|
||||
{
|
||||
impl<S> FromRequestParts<S> for CookieJar {
|
||||
type Rejection = Infallible;
|
||||
|
||||
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
|
||||
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
|
||||
Ok(Self::from_headers(&parts.headers))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use axum::{
|
||||
rejection::{FailedToDeserializeQueryString, FormRejection, InvalidFormContentType},
|
||||
FromRequest,
|
||||
},
|
||||
BoxError,
|
||||
BoxError, RequestExt,
|
||||
};
|
||||
use bytes::Bytes;
|
||||
use http::{header, HeaderMap, Method, Request};
|
||||
@@ -61,11 +61,10 @@ where
|
||||
B: HttpBody + Send + 'static,
|
||||
B::Data: Send,
|
||||
B::Error: Into<BoxError>,
|
||||
S: Send + Sync,
|
||||
{
|
||||
type Rejection = FormRejection;
|
||||
|
||||
async fn from_request(req: Request<B>, state: &S) -> Result<Self, Self::Rejection> {
|
||||
async fn from_request(req: Request<B>, _: &S) -> Result<Self, Self::Rejection> {
|
||||
if req.method() == Method::GET {
|
||||
let query = req.uri().query().unwrap_or_default();
|
||||
let value = serde_html_form::from_str(query)
|
||||
@@ -76,7 +75,7 @@ where
|
||||
return Err(InvalidFormContentType::default().into());
|
||||
}
|
||||
|
||||
let bytes = Bytes::from_request(req, state).await?;
|
||||
let bytes: Bytes = req.extract().await?;
|
||||
let value = serde_html_form::from_bytes(&bytes)
|
||||
.map_err(FailedToDeserializeQueryString::__private_new)?;
|
||||
|
||||
|
||||
@@ -62,11 +62,10 @@ pub struct Query<T>(pub T);
|
||||
impl<T, S> FromRequestParts<S> for Query<T>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
S: Send + Sync,
|
||||
{
|
||||
type Rejection = QueryRejection;
|
||||
|
||||
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
|
||||
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
|
||||
let query = parts.uri.query().unwrap_or_default();
|
||||
let value = serde_html_form::from_str(query)
|
||||
.map_err(FailedToDeserializeQueryString::__private_new)?;
|
||||
|
||||
@@ -154,15 +154,12 @@ mod tests {
|
||||
struct TestRejection;
|
||||
|
||||
#[async_trait]
|
||||
impl<S> FromRequestParts<S> for TestExtractor
|
||||
where
|
||||
S: Send + Sync,
|
||||
{
|
||||
impl<S> FromRequestParts<S> for TestExtractor {
|
||||
type Rejection = ();
|
||||
|
||||
async fn from_request_parts(
|
||||
_parts: &mut Parts,
|
||||
_state: &S,
|
||||
_: &S,
|
||||
) -> Result<Self, Self::Rejection> {
|
||||
Err(())
|
||||
}
|
||||
|
||||
@@ -106,11 +106,10 @@ where
|
||||
B::Data: Into<Bytes>,
|
||||
B::Error: Into<BoxError>,
|
||||
T: DeserializeOwned,
|
||||
S: Send + Sync,
|
||||
{
|
||||
type Rejection = Infallible;
|
||||
|
||||
async fn from_request(req: Request<B>, _state: &S) -> Result<Self, Self::Rejection> {
|
||||
async fn from_request(req: Request<B>, _: &S) -> Result<Self, Self::Rejection> {
|
||||
// `Stream::lines` isn't a thing so we have to convert it into an `AsyncRead`
|
||||
// so we can call `AsyncRead::lines` and then convert it back to a `Stream`
|
||||
let body = BodyStream {
|
||||
|
||||
@@ -5,7 +5,7 @@ use axum::{
|
||||
body::{Bytes, HttpBody},
|
||||
extract::{rejection::BytesRejection, FromRequest},
|
||||
response::{IntoResponse, Response},
|
||||
BoxError,
|
||||
BoxError, RequestExt,
|
||||
};
|
||||
use bytes::BytesMut;
|
||||
use http::{Request, StatusCode};
|
||||
@@ -103,12 +103,11 @@ where
|
||||
B: HttpBody + Send + 'static,
|
||||
B::Data: Send,
|
||||
B::Error: Into<BoxError>,
|
||||
S: Send + Sync,
|
||||
{
|
||||
type Rejection = ProtoBufRejection;
|
||||
|
||||
async fn from_request(req: Request<B>, state: &S) -> Result<Self, Self::Rejection> {
|
||||
let mut bytes = Bytes::from_request(req, state).await?;
|
||||
async fn from_request(req: Request<B>, _: &S) -> Result<Self, Self::Rejection> {
|
||||
let mut bytes: Bytes = req.extract().await?;
|
||||
|
||||
match T::decode(&mut bytes) {
|
||||
Ok(value) => Ok(ProtoBuf(value)),
|
||||
|
||||
Reference in New Issue
Block a user