Skip to content

Commit 5b46f4d

Browse files
committed
Replace once_cell with std::sync::OnceLock
1 parent 215baee commit 5b46f4d

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

refinery_core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ mysql_async = ["dep:mysql_async"]
2020
async-trait = "0.1"
2121
cfg-if = "1.0"
2222
log = "0.4"
23-
once_cell = "1"
2423
regex = "1"
2524
serde = { version = "1", features = ["derive"] }
2625
siphasher = "1.0"

refinery_core/src/runner.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
use once_cell::sync::Lazy;
21
use regex::Regex;
32
use siphasher::sip::SipHasher13;
43
use time::OffsetDateTime;
54

65
use std::cmp::Ordering;
76
use std::fmt;
87
use std::hash::{Hash, Hasher};
8+
use std::sync::OnceLock;
99

1010
use crate::error::Kind;
1111
use crate::traits::DEFAULT_MIGRATION_TABLE_NAME;
1212
use crate::{AsyncMigrate, Error, Migrate};
1313
use std::fmt::Formatter;
1414

1515
// regex used to match file names
16-
pub fn file_match_re() -> Regex {
17-
Regex::new(r"^([U|V])(\d+(?:\.\d+)?)__(\w+)").unwrap()
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())
1819
}
1920

20-
pub(crate) static RE: Lazy<regex::Regex> = Lazy::new(file_match_re);
21-
2221
/// An enum set that represents the type of the Migration
2322
#[derive(Clone, PartialEq)]
2423
pub enum Type {
@@ -83,7 +82,7 @@ impl Migration {
8382
/// Create an unapplied migration, name and version are parsed from the input_name,
8483
/// which must be named in the format (U|V){1}__{2}.rs where {1} represents the migration version and {2} the name.
8584
pub fn unapplied(input_name: &str, sql: &str) -> Result<Migration, Error> {
86-
let captures = RE
85+
let captures = file_match_re()
8786
.captures(input_name)
8887
.filter(|caps| caps.len() == 4)
8988
.ok_or_else(|| Error::new(Kind::InvalidName, None))?;

refinery_core/src/util.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
use crate::error::{Error, Kind};
2-
use once_cell::sync::Lazy;
32
use regex::Regex;
43
use std::ffi::OsStr;
54
use std::path::{Path, PathBuf};
65
use walkdir::{DirEntry, WalkDir};
76

8-
pub(crate) static RE: Lazy<regex::Regex> =
9-
Lazy::new(|| Regex::new(r"^(U|V)(\d+(?:\.\d+)?)__\w+\.(rs|sql)$").unwrap());
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)