use ready macro

This commit is contained in:
fakeshadow 2020-12-16 07:10:53 +08:00
parent 936e12cc9d
commit 13aa374703
1 changed files with 9 additions and 9 deletions

View File

@ -5,6 +5,7 @@ use std::task::{Context, Poll};
use actix_http::error::Error; use actix_http::error::Error;
use futures_util::future::{ready, Ready}; use futures_util::future::{ready, Ready};
use futures_util::ready;
use crate::dev::Payload; use crate::dev::Payload;
use crate::request::HttpRequest; use crate::request::HttpRequest;
@ -121,13 +122,14 @@ where
type Output = Result<Option<T>, Error>; type Output = Result<Option<T>, Error>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match self.project().fut.poll(cx) { let this = self.project();
Poll::Ready(Ok(t)) => Poll::Ready(Ok(Some(t))), let res = ready!(this.fut.poll(cx));
Poll::Ready(Err(e)) => { match res {
Ok(t) => Poll::Ready(Ok(Some(t))),
Err(e) => {
log::debug!("Error for Option<T> extractor: {}", e.into()); log::debug!("Error for Option<T> extractor: {}", e.into());
Poll::Ready(Ok(None)) Poll::Ready(Ok(None))
} }
Poll::Pending => Poll::Pending,
} }
} }
} }
@ -209,11 +211,9 @@ where
type Output = Result<Result<T, E>, Error>; type Output = Result<Result<T, E>, Error>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match self.project().fut.poll(cx) { let this = self.project();
Poll::Ready(Ok(t)) => Poll::Ready(Ok(Ok(t))), let res = ready!(this.fut.poll(cx));
Poll::Ready(Err(e)) => Poll::Ready(Ok(Err(e))), Poll::Ready(Ok(res))
Poll::Pending => Poll::Pending,
}
} }
} }