Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace lazy_static with std::sync::OnceLock #301

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading