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.
This commit is contained in:
Nick Groenen 2024-08-04 11:52:20 +02:00
parent 6601810d2b
commit c32d70ac06
No known key found for this signature in database
GPG Key ID: 4F0AD019928AE098
4 changed files with 10 additions and 13 deletions

1
Cargo.lock generated
View File

@ -360,7 +360,6 @@ dependencies = [
"eyre", "eyre",
"gumdrop", "gumdrop",
"ignore", "ignore",
"lazy_static",
"matter", "matter",
"pathdiff", "pathdiff",
"percent-encoding", "percent-encoding",

View File

@ -28,7 +28,6 @@ doc = false
eyre = "0.6.12" eyre = "0.6.12"
gumdrop = "0.8.1" gumdrop = "0.8.1"
ignore = "0.4.22" ignore = "0.4.22"
lazy_static = "1.5.0"
matter = "0.1.0-alpha4" matter = "0.1.0-alpha4"
pathdiff = "0.2.1" pathdiff = "0.2.1"
percent-encoding = "2.3.1" percent-encoding = "2.3.1"

View File

@ -1,8 +1,5 @@
pub use {pulldown_cmark, serde_yaml}; pub use {pulldown_cmark, serde_yaml};
#[macro_use]
extern crate lazy_static;
mod context; mod context;
mod frontmatter; mod frontmatter;
pub mod postprocessors; pub mod postprocessors;
@ -898,20 +895,22 @@ fn codeblock_kind_to_owned<'a>(codeblock_kind: CodeBlockKind<'_>) -> CodeBlockKi
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::sync::LazyLock;
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use rstest::rstest; use rstest::rstest;
use super::*; use super::*;
lazy_static! { static VAULT: LazyLock<Vec<PathBuf>> = LazyLock::new(|| {
static ref VAULT: Vec<PathBuf> = vec![ vec![
PathBuf::from("NoteA.md"), PathBuf::from("NoteA.md"),
PathBuf::from("Document.pdf"), PathBuf::from("Document.pdf"),
PathBuf::from("Note.1.md"), PathBuf::from("Note.1.md"),
PathBuf::from("nested/NoteA.md"), PathBuf::from("nested/NoteA.md"),
PathBuf::from("Note\u{E4}.md"), // Noteä.md, see also encodings() below PathBuf::from("Note\u{E4}.md"), // Noteä.md, see also encodings() below
]; ]
} });
#[test] #[test]
#[allow(clippy::unicode_not_nfc)] #[allow(clippy::unicode_not_nfc)]

View File

@ -1,11 +1,11 @@
use std::fmt; use std::fmt;
use std::sync::LazyLock;
use regex::Regex; use regex::Regex;
lazy_static! { static OBSIDIAN_NOTE_LINK_RE: LazyLock<Regex> = LazyLock::new(|| {
static ref OBSIDIAN_NOTE_LINK_RE: Regex = Regex::new(r"^(?P<file>[^#|]+)??(#(?P<section>.+?))??(\|(?P<label>.+?))??$").unwrap()
Regex::new(r"^(?P<file>[^#|]+)??(#(?P<section>.+?))??(\|(?P<label>.+?))??$").unwrap(); });
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
/// `ObsidianNoteReference` represents the structure of a `[[note]]` or `![[embed]]` reference. /// `ObsidianNoteReference` represents the structure of a `[[note]]` or `![[embed]]` reference.