From 13aa374703e7ca50cb456da8b3ea2c859ab9c278 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Wed, 16 Dec 2020 07:10:53 +0800 Subject: [PATCH] use ready macro --- src/extract.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/extract.rs b/src/extract.rs index c13e9da44..5916b1bc5 100644 --- a/src/extract.rs +++ b/src/extract.rs @@ -5,6 +5,7 @@ use std::task::{Context, Poll}; use actix_http::error::Error; use futures_util::future::{ready, Ready}; +use futures_util::ready; use crate::dev::Payload; use crate::request::HttpRequest; @@ -121,13 +122,14 @@ where type Output = Result, Error>; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - match self.project().fut.poll(cx) { - Poll::Ready(Ok(t)) => Poll::Ready(Ok(Some(t))), - Poll::Ready(Err(e)) => { + let this = self.project(); + let res = ready!(this.fut.poll(cx)); + match res { + Ok(t) => Poll::Ready(Ok(Some(t))), + Err(e) => { log::debug!("Error for Option extractor: {}", e.into()); Poll::Ready(Ok(None)) } - Poll::Pending => Poll::Pending, } } } @@ -209,11 +211,9 @@ where type Output = Result, Error>; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - match self.project().fut.poll(cx) { - Poll::Ready(Ok(t)) => Poll::Ready(Ok(Ok(t))), - Poll::Ready(Err(e)) => Poll::Ready(Ok(Err(e))), - Poll::Pending => Poll::Pending, - } + let this = self.project(); + let res = ready!(this.fut.poll(cx)); + Poll::Ready(Ok(res)) } }