Skip to content

Commit

Permalink
Merge pull request #395 from siketyan/refactor/GH-386
Browse files Browse the repository at this point in the history
refactor: Replace lazy_static with std::sync::OnceLock
  • Loading branch information
siketyan authored Jul 1, 2024
2 parents 5087ae0 + 77bc813 commit 9e24cb3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ dirs = "5.0"
git2 = "0.19.0"
itertools = "0.13.0"
indicatif = "0.17.8"
lazy_static = "1.5"
nucleo-matcher = "0.3.1"
regex = "1.10"
serde = { version = "1.0", features = ["derive"] }
Expand Down
24 changes: 23 additions & 1 deletion src/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::str::FromStr;
use anyhow::{anyhow, Error, Result};
use itertools::FoldWhile;
use itertools::Itertools;
use lazy_static::lazy_static;
use regex::Regex;
use serde::Deserialize;
use serde_with::DeserializeFromStr;
Expand All @@ -15,6 +14,29 @@ const GITHUB_COM: &str = "github.com";
const GIT_EXTENSION: &str = ".git";
const EXTENSIONS: &[&str] = &[GIT_EXTENSION];

macro_rules! lazy_static {
($(static ref $name:ident : $ty:ty = $value:expr ;)*) => {
$(
#[doc(hidden)]
#[allow(dead_code, non_camel_case_types, clippy::upper_case_acronyms)]
struct $name { __private: () }

impl ::std::ops::Deref for $name {
type Target = $ty;

fn deref(&self) -> &Self::Target {
use std::sync::OnceLock;
static LAZY: OnceLock<$ty> = OnceLock::new();
LAZY.get_or_init(|| $value)
}
}

#[allow(non_camel_case_types)]
const $name: $name = $name { __private: () };
)*
};
}

lazy_static! {
static ref SSH: Pattern = Pattern::from(
Regex::new(r"^(?P<user>[0-9A-Za-z\-]+)@(?P<host>[0-9A-Za-z\.\-]+):(?P<owner>[0-9A-Za-z_\.\-]+)/(?P<repo>[0-9A-Za-z_\.\-]+)$")
Expand Down

0 comments on commit 9e24cb3

Please sign in to comment.