Skip to content

Commit

Permalink
Replace lazy_static with std::sync::OnceLock (#301)
Browse files Browse the repository at this point in the history
* Replace lazy_static with once_cell

* Replace once_cell with std::sync::OnceLock
  • Loading branch information
serprex authored Dec 29, 2023
1 parent c16551b commit 3a4a22b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
1 change: 0 additions & 1 deletion refinery_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ mysql_async = ["dep:mysql_async"]
[dependencies]
async-trait = "0.1"
cfg-if = "1.0"
lazy_static = "1"
log = "0.4"
regex = "1"
serde = { version = "1", features = ["derive"] }
Expand Down
12 changes: 5 additions & 7 deletions refinery_core/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@ use time::OffsetDateTime;
use std::cmp::Ordering;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::sync::OnceLock;

use crate::error::Kind;
use crate::traits::DEFAULT_MIGRATION_TABLE_NAME;
use crate::{AsyncMigrate, Error, Migrate};
use std::fmt::Formatter;

// regex used to match file names
pub fn file_match_re() -> Regex {
Regex::new(r"^([U|V])(\d+(?:\.\d+)?)__(\w+)").unwrap()
}

lazy_static::lazy_static! {
static ref RE: regex::Regex = file_match_re();
pub fn file_match_re() -> &'static Regex {
static RE: OnceLock<regex::Regex> = OnceLock::new();
RE.get_or_init(|| Regex::new(r"^([U|V])(\d+(?:\.\d+)?)__(\w+)").unwrap())
}

/// An enum set that represents the type of the Migration
Expand Down Expand Up @@ -84,7 +82,7 @@ impl Migration {
/// Create an unapplied migration, name and version are parsed from the input_name,
/// which must be named in the format (U|V){1}__{2}.rs where {1} represents the migration version and {2} the name.
pub fn unapplied(input_name: &str, sql: &str) -> Result<Migration, Error> {
let captures = RE
let captures = file_match_re()
.captures(input_name)
.filter(|caps| caps.len() == 4)
.ok_or_else(|| Error::new(Kind::InvalidName, None))?;
Expand Down
4 changes: 0 additions & 4 deletions refinery_core/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use walkdir::{DirEntry, WalkDir};

lazy_static::lazy_static! {
static ref RE: regex::Regex = Regex::new(r"^(U|V)(\d+(?:\.\d+)?)__\w+\.(rs|sql)$").unwrap();
}

/// enum containing the migration types used to search for migrations
/// either just .sql files or both .sql and .rs
pub enum MigrationType {
Expand Down

0 comments on commit 3a4a22b

Please sign in to comment.