Make extractors easier to write (#36)

Previously extractors worked directly on `Request<B>` which meant you
had to do weird tricks like `mem::take(req.headers_mut())` to get owned
parts of the request.

This changes that instead to use a new `RequestParts` type that have
methods to "take" each part of the request. Without having to do weird
tricks.

Also removed the need to have `B: Default` for body extractors.
This commit is contained in:
David Pedersen
2021-07-22 13:23:50 +02:00
committed by GitHub
parent e544fe1c39
commit f32d325e55
12 changed files with 441 additions and 193 deletions
+2 -2
View File
@@ -87,7 +87,7 @@
//! [load shed]: tower::load_shed
use crate::{
body::BoxBody,
body::{box_body, BoxBody},
response::IntoResponse,
routing::{EmptyRouter, MethodFilter, RouteFuture},
};
@@ -656,7 +656,7 @@ where
fn poll(self: std::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let res = ready!(self.project().0.poll(cx))?;
let res = res.map(BoxBody::new);
let res = res.map(box_body);
Poll::Ready(Ok(res))
}
}