Pass the user manager by reference

Serving a request now takes 0 arc clones!
This commit is contained in:
Emi Tatsuo 2020-12-15 10:27:33 -05:00
parent 597bc6aa6b
commit e49b71b6d2
Signed by: Emi
GPG key ID: 68FAB2E2E6DFC98B
2 changed files with 9 additions and 9 deletions

View file

@ -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<Request> {
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<Request> {
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,
)?
)
}

View file

@ -39,7 +39,7 @@ pub struct Request {
certificate: Option<[u8; 32]>,
trailing_segments: Option<Vec<String>>,
#[cfg(feature="user_management")]
manager: UserManager,
manager: &'static UserManager,
#[cfg(feature = "scgi_srv")]
headers: HashMap<String, String>,
#[cfg(feature = "scgi_srv")]
@ -80,7 +80,7 @@ impl Request {
#[cfg(feature = "scgi_srv")]
headers: HashMap<String, String>,
#[cfg(feature="user_management")]
manager: UserManager,
manager: &'static UserManager,
) -> Result<Self> {
#[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