From c32d70ac069ca7859d913713fd3f2ba1874e546e Mon Sep 17 00:00:00 2001 From: Nick Groenen Date: Sun, 4 Aug 2024 11:52:20 +0200 Subject: [PATCH] Use std::sync::LazyLock instead of lazy_static crate LazyLock was stabilized in Rust 1.80.0, allowing us to drop this external dependency now. --- Cargo.lock | 1 - Cargo.toml | 1 - src/lib.rs | 13 ++++++------- src/references.rs | 8 ++++---- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 40b0958..c701165 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -360,7 +360,6 @@ dependencies = [ "eyre", "gumdrop", "ignore", - "lazy_static", "matter", "pathdiff", "percent-encoding", diff --git a/Cargo.toml b/Cargo.toml index 9e87ee7..1dc2719 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,6 @@ doc = false eyre = "0.6.12" gumdrop = "0.8.1" ignore = "0.4.22" -lazy_static = "1.5.0" matter = "0.1.0-alpha4" pathdiff = "0.2.1" percent-encoding = "2.3.1" diff --git a/src/lib.rs b/src/lib.rs index a8265e1..ff6f111 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,5 @@ pub use {pulldown_cmark, serde_yaml}; -#[macro_use] -extern crate lazy_static; - mod context; mod frontmatter; pub mod postprocessors; @@ -898,20 +895,22 @@ fn codeblock_kind_to_owned<'a>(codeblock_kind: CodeBlockKind<'_>) -> CodeBlockKi #[cfg(test)] mod tests { + use std::sync::LazyLock; + use pretty_assertions::assert_eq; use rstest::rstest; use super::*; - lazy_static! { - static ref VAULT: Vec = vec![ + static VAULT: LazyLock> = LazyLock::new(|| { + vec![ PathBuf::from("NoteA.md"), PathBuf::from("Document.pdf"), PathBuf::from("Note.1.md"), PathBuf::from("nested/NoteA.md"), PathBuf::from("Note\u{E4}.md"), // NoteƤ.md, see also encodings() below - ]; - } + ] + }); #[test] #[allow(clippy::unicode_not_nfc)] diff --git a/src/references.rs b/src/references.rs index 1d7e731..26e8d96 100644 --- a/src/references.rs +++ b/src/references.rs @@ -1,11 +1,11 @@ use std::fmt; +use std::sync::LazyLock; use regex::Regex; -lazy_static! { - static ref OBSIDIAN_NOTE_LINK_RE: Regex = - Regex::new(r"^(?P[^#|]+)??(#(?P
.+?))??(\|(?P