diff options
author | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-08-29 11:10:27 +0200 |
---|---|---|
committer | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-08-29 11:10:27 +0200 |
commit | 873f64b2e2183c389c4c6476a4f90f63a4513cc5 (patch) | |
tree | b0464435684ef789c6dfc55e2b0569a29009318b | |
parent | 161b052713f5cee08f20ce6ade0881e274c47fdd (diff) |
Eliminate dependency on lazy_static
-rw-r--r-- | Cargo.lock | 7 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/cmd/folders.rs | 24 | ||||
-rw-r--r-- | src/cmd/list.rs | 2 |
4 files changed, 14 insertions, 20 deletions
@@ -301,7 +301,6 @@ version = "0.6.0" dependencies = [ "chrono", "clap", - "lazy_static", "libc", "log", "maildir", @@ -312,12 +311,6 @@ dependencies = [ ] [[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] name = "libc" version = "0.2.140" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -16,7 +16,6 @@ libc = "0.2" maildir = "0.6" serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -lazy_static = "1.4" mailparse = "0.14" chrono = "0.4" clap = { version = "4.0", features = ["derive"] } diff --git a/src/cmd/folders.rs b/src/cmd/folders.rs index 7bf93f1..0133528 100644 --- a/src/cmd/folders.rs +++ b/src/cmd/folders.rs @@ -1,23 +1,25 @@ use std::collections::BTreeSet; use std::ffi::{OsStr, OsString}; use std::path::Path; +use std::sync::OnceLock; -use lazy_static::lazy_static; use maildir::Maildir; use crate::error::Result; -lazy_static! { - static ref REQUIRED_MAILDIR_DIRS: BTreeSet<OsString> = [ - OsString::from("cur"), - "new".into(), - "tmp".into(), - "maildirfolder".into(), - ] - .into(); -} +static REQUIRED_MAILDIR_DIRS: OnceLock<BTreeSet<OsString>> = OnceLock::new(); fn is_mailsubdir(p: &Path) -> bool { + let rmd = REQUIRED_MAILDIR_DIRS.get_or_init(|| { + [ + OsString::from("cur"), + "new".into(), + "tmp".into(), + "maildirfolder".into(), + ] + .into() + }); + p.is_dir() && p.file_name() .map_or(false, |fname| fname.to_string_lossy().starts_with('.')) @@ -29,7 +31,7 @@ fn is_mailsubdir(p: &Path) -> bool { .and_then(|dir_entry| dir_entry.path().file_name().map(OsStr::to_owned)) }) .collect::<BTreeSet<_>>() - .is_superset(&REQUIRED_MAILDIR_DIRS) + .is_superset(rmd) }) .unwrap_or_default() } diff --git a/src/cmd/list.rs b/src/cmd/list.rs index 0ec0389..b77a311 100644 --- a/src/cmd/list.rs +++ b/src/cmd/list.rs @@ -24,7 +24,7 @@ fn mid_to_rec_time(mid: &str) -> f64 { warn!("Invaild mail-id {}", mid); return 0.0; }; - let Some(sep) = mid[dec+1..].find('.') else { + let Some(sep) = mid[dec + 1..].find('.') else { return 0.0; }; mid[..dec + 1 + sep].parse().unwrap() |