Skip to content

Commit 3a4a22b

Browse files
authored
Replace lazy_static with std::sync::OnceLock (#301)
* Replace lazy_static with once_cell * Replace once_cell with std::sync::OnceLock
1 parent c16551b commit 3a4a22b

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

refinery_core/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ mysql_async = ["dep:mysql_async"]
1919
[dependencies]
2020
async-trait = "0.1"
2121
cfg-if = "1.0"
22-
lazy_static = "1"
2322
log = "0.4"
2423
regex = "1"
2524
serde = { version = "1", features = ["derive"] }

refinery_core/src/runner.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@ use time::OffsetDateTime;
55
use std::cmp::Ordering;
66
use std::fmt;
77
use std::hash::{Hash, Hasher};
8+
use std::sync::OnceLock;
89

910
use crate::error::Kind;
1011
use crate::traits::DEFAULT_MIGRATION_TABLE_NAME;
1112
use crate::{AsyncMigrate, Error, Migrate};
1213
use std::fmt::Formatter;
1314

1415
// regex used to match file names
15-
pub fn file_match_re() -> Regex {
16-
Regex::new(r"^([U|V])(\d+(?:\.\d+)?)__(\w+)").unwrap()
17-
}
18-
19-
lazy_static::lazy_static! {
20-
static ref RE: regex::Regex = file_match_re();
16+
pub fn file_match_re() -> &'static Regex {
17+
static RE: OnceLock<regex::Regex> = OnceLock::new();
18+
RE.get_or_init(|| Regex::new(r"^([U|V])(\d+(?:\.\d+)?)__(\w+)").unwrap())
2119
}
2220

2321
/// An enum set that represents the type of the Migration
@@ -84,7 +82,7 @@ impl Migration {
8482
/// Create an unapplied migration, name and version are parsed from the input_name,
8583
/// which must be named in the format (U|V){1}__{2}.rs where {1} represents the migration version and {2} the name.
8684
pub fn unapplied(input_name: &str, sql: &str) -> Result<Migration, Error> {
87-
let captures = RE
85+
let captures = file_match_re()
8886
.captures(input_name)
8987
.filter(|caps| caps.len() == 4)
9088
.ok_or_else(|| Error::new(Kind::InvalidName, None))?;

refinery_core/src/util.rs

-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ use std::ffi::OsStr;
44
use std::path::{Path, PathBuf};
55
use walkdir::{DirEntry, WalkDir};
66

7-
lazy_static::lazy_static! {
8-
static ref RE: regex::Regex = Regex::new(r"^(U|V)(\d+(?:\.\d+)?)__\w+\.(rs|sql)$").unwrap();
9-
}
10-
117
/// enum containing the migration types used to search for migrations
128
/// either just .sql files or both .sql and .rs
139
pub enum MigrationType {

0 commit comments

Comments
 (0)