From e49b71b6d263885f619640b0a715be6b1317bc4b Mon Sep 17 00:00:00 2001 From: Emi Tatsuo Date: Tue, 15 Dec 2020 10:27:33 -0500 Subject: [PATCH] Pass the user manager by reference Serving a request now takes 0 arc clones! --- src/lib.rs | 10 +++++----- src/types/request.rs | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f9d97be..17f1c10 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -313,7 +313,7 @@ impl ServerInner { } async fn serve_client( - &self, + &'static self, #[cfg(feature = "gemini_srv")] stream: TcpStream, #[cfg(all(feature = "scgi_srv", not(feature = "gemini_srv")))] @@ -498,7 +498,7 @@ impl ServerInner { #[cfg(feature = "gemini_srv")] async fn receive_request( - &self, + &'static self, stream: &mut (impl AsyncBufRead + Unpin + Send), ) -> Result { const HEADER_LIMIT: usize = REQUEST_URI_MAX_LEN + "\r\n".len(); @@ -526,13 +526,13 @@ impl ServerInner { Request::new( uri, #[cfg(feature="user_management")] - self.manager.clone(), + &self.manager, ).context("Failed to create request from URI") } #[cfg(feature = "scgi_srv")] async fn receive_request( - &self, + &'static self, stream: &mut (impl AsyncBufRead + Unpin), ) -> Result { let mut buff = Vec::with_capacity(4); @@ -600,7 +600,7 @@ impl ServerInner { Request::new( headers, #[cfg(feature = "user_management")] - self.manager.clone(), + &self.manager, )? ) } diff --git a/src/types/request.rs b/src/types/request.rs index fb9367a..bb0cd11 100644 --- a/src/types/request.rs +++ b/src/types/request.rs @@ -39,7 +39,7 @@ pub struct Request { certificate: Option<[u8; 32]>, trailing_segments: Option>, #[cfg(feature="user_management")] - manager: UserManager, + manager: &'static UserManager, #[cfg(feature = "scgi_srv")] headers: HashMap, #[cfg(feature = "scgi_srv")] @@ -80,7 +80,7 @@ impl Request { #[cfg(feature = "scgi_srv")] headers: HashMap, #[cfg(feature="user_management")] - manager: UserManager, + manager: &'static UserManager, ) -> Result { #[cfg(feature = "scgi_srv")] #[allow(clippy::or_fun_call)] // Lay off it's a macro @@ -267,8 +267,8 @@ impl Request { /// Expose the server's UserManager /// /// Can be used to query users, or directly access the database - pub fn user_manager(&self) -> &UserManager { - &self.manager + pub fn user_manager(&self) -> &'static UserManager { + self.manager } /// Attempt to rewrite an absolute URL against the base path of the SCGI script