actix_msgpack/
msgpack_extractor_future.rs1use crate::{ErrorHandler, MsgPack, MsgPackMessage};
2use actix_web::{error::Error, HttpRequest};
3use serde::de::DeserializeOwned;
4use std::{
5 future::Future,
6 pin::Pin,
7 task::{Context, Poll},
8};
9
10pub struct MsgPackExtractorFuture<T> {
11 pub req: HttpRequest,
12 pub fut: MsgPackMessage<T>,
13 pub err_handler: Option<ErrorHandler>,
14}
15
16impl<T: DeserializeOwned + 'static> Future for MsgPackExtractorFuture<T> {
17 type Output = Result<MsgPack<T>, Error>;
18
19 fn poll(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Self::Output> {
20 let this = self.get_mut();
21 let res = match Pin::new(&mut this.fut).poll(ctx) {
22 Poll::Ready(data) => data,
23 Poll::Pending => return Poll::Pending,
24 };
25
26 let res = match res {
27 Err(err) => {
28 if let Some(err_handler) = this.err_handler.as_ref() {
29 Err((*err_handler)(err, &this.req))
30 } else {
31 Err(err.into())
32 }
33 },
34 Ok(data) => Ok(MsgPack(data)),
35 };
36
37 Poll::Ready(res)
38 }
39}