From 1c0b5a23d4c29f39e9230293e1275308c939ceab Mon Sep 17 00:00:00 2001 From: javalsai Date: Sat, 21 Mar 2026 19:13:17 +0100 Subject: [PATCH] remove: needless clone --- src/main.rs | 3 ++- src/server/caches/mime.rs | 10 +++++----- src/server/caches/mod.rs | 4 ++-- src/server/mod.rs | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6fb55e5..4188c36 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,10 @@ +// dead rust-lang/rustfmt/pull/5394 :( #![feature( decl_macro, duration_constructors, never_type, once_cell_try, - seek_stream_len, + seek_stream_len )] #![allow(clippy::future_not_send)] // will get to fix these later diff --git a/src/server/caches/mime.rs b/src/server/caches/mime.rs index 0e76ca5..afa2151 100644 --- a/src/server/caches/mime.rs +++ b/src/server/caches/mime.rs @@ -16,11 +16,11 @@ pub enum NewCookieError { // MimeDBPath(#[from] magic::cookie::InvalidDatabasePathError), } -pub struct Mime { - magic_dbs: magic::cookie::DatabasePaths, +pub struct Mime<'a> { + magic_dbs: &'a magic::cookie::DatabasePaths, } -impl Mime { +impl<'a> Mime<'a> { thread_local! { static COOKIE_CELL: OnceCell> = const { OnceCell::new() }; } @@ -32,7 +32,7 @@ impl Mime { Self::COOKIE_CELL.with(|cookie| { let may_cookie = cookie.get_or_try_init::<_, NewCookieError>(move || { let cookie = magic::Cookie::open(magic::cookie::Flags::MIME)?; - Ok(cookie.load(&self.magic_dbs)?) + Ok(cookie.load(self.magic_dbs)?) }); match may_cookie { @@ -43,7 +43,7 @@ impl Mime { } #[must_use] - pub const fn new(magic_dbs: magic::cookie::DatabasePaths) -> Self { + pub const fn new(magic_dbs: &'a magic::cookie::DatabasePaths) -> Self { Self { magic_dbs } } diff --git a/src/server/caches/mod.rs b/src/server/caches/mod.rs index 6363504..2985803 100644 --- a/src/server/caches/mod.rs +++ b/src/server/caches/mod.rs @@ -28,7 +28,7 @@ pub struct AppCache<'a> { // FIXME: blocks user_cache: UsersCache, // FIXME: blocks - magic_mime_cookie: Mime, + magic_mime_cookie: Mime<'a>, /// MUST only contain users from an accepted group, we do not want to cache arbitrary usernames /// and blow memory up. @@ -47,7 +47,7 @@ impl<'a> AppCache<'a> { /// If weighter's usize doesn't fit in its u32 #[must_use] pub fn new( - magic_dbs: magic::cookie::DatabasePaths, + magic_dbs: &'a magic::cookie::DatabasePaths, only_groups: &'a [crate::serdes::Group], ) -> Self { Self { diff --git a/src/server/mod.rs b/src/server/mod.rs index b1951c2..d52fbe0 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -19,7 +19,7 @@ pub async fn start_app(args: crate::args::Args, config: crate::conf::Config) -> let config = Box::leak(Box::new(config)); let cache = caches::AppCache::new( - config.unix.magic_paths.clone(), + &config.unix.magic_paths, &config.unix.groups, );