Add extractor_middleware (#29)

Converts an extractor into a middleware so it can be run for many routes
without having to repeat it in the function signature.
This commit is contained in:
David Pedersen
2021-07-09 23:38:59 +02:00
committed by GitHub
parent 0c19fa4d52
commit 1cbd43cfc4
3 changed files with 322 additions and 3 deletions
+8 -2
View File
@@ -189,8 +189,12 @@ use std::{
task::{Context, Poll},
};
pub mod extractor_middleware;
pub mod rejection;
#[doc(inline)]
pub use self::extractor_middleware::extractor_middleware;
/// Types that can be created from requests.
///
/// See the [module docs](crate::extract) for more details.
@@ -840,12 +844,14 @@ macro_rules! impl_parse_url {
impl_parse_url!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16);
/// Request extension used to indicate that body has been extracted and `Default` has been left in
/// its place.
struct BodyAlreadyExtractedExt;
fn take_body<B>(req: &mut Request<B>) -> Result<B, BodyAlreadyExtracted>
where
B: Default,
{
struct BodyAlreadyExtractedExt;
if req
.extensions_mut()
.insert(BodyAlreadyExtractedExt)