From 5fe0777318c00899ff8266a3641592080ecfe4cf Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 24 Jan 2023 11:22:27 +0100 Subject: [PATCH] rest-server: drop allocation in Service impl Signed-off-by: Wolfgang Bumiller --- proxmox-rest-server/src/rest.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/proxmox-rest-server/src/rest.rs b/proxmox-rest-server/src/rest.rs index 57e97623..01ce3d7f 100644 --- a/proxmox-rest-server/src/rest.rs +++ b/proxmox-rest-server/src/rest.rs @@ -7,7 +7,7 @@ use std::sync::{Arc, Mutex}; use std::task::{Context, Poll}; use anyhow::{bail, format_err, Error}; -use futures::future::{self, FutureExt, TryFutureExt}; +use futures::future::{FutureExt, TryFutureExt}; use futures::stream::TryStreamExt; use hyper::body::HttpBody; use hyper::header::{self, HeaderMap}; @@ -79,21 +79,20 @@ impl RestServer { impl Service<&T> for RestServer { type Response = ApiService; type Error = Error; - type Future = Pin> + Send>>; + type Future = std::future::Ready>; fn poll_ready(&mut self, _cx: &mut Context) -> Poll> { Poll::Ready(Ok(())) } fn call(&mut self, ctx: &T) -> Self::Future { - let result = match ctx.peer_addr() { + std::future::ready(match ctx.peer_addr() { Err(err) => Err(format_err!("unable to get peer address - {}", err)), Ok(peer) => Ok(ApiService { peer, api_config: self.api_config.clone(), }), - }; - Box::pin(async move { result }) + }) } }