Skip to content

Commit

Permalink
Replace once_cell with std::sync::OnceLock
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Dec 28, 2023
1 parent 215baee commit 5b46f4d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
1 change: 0 additions & 1 deletion refinery_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ mysql_async = ["dep:mysql_async"]
async-trait = "0.1"
cfg-if = "1.0"
log = "0.4"
once_cell = "1"
regex = "1"
serde = { version = "1", features = ["derive"] }
siphasher = "1.0"
Expand Down
11 changes: 5 additions & 6 deletions refinery_core/src/runner.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
use once_cell::sync::Lazy;
use regex::Regex;
use siphasher::sip::SipHasher13;
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()
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())
}

pub(crate) static RE: Lazy<regex::Regex> = Lazy::new(file_match_re);

/// An enum set that represents the type of the Migration
#[derive(Clone, PartialEq)]
pub enum Type {
Expand Down Expand Up @@ -83,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
@@ -1,13 +1,9 @@
use crate::error::{Error, Kind};
use once_cell::sync::Lazy;
use regex::Regex;
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use walkdir::{DirEntry, WalkDir};

pub(crate) static RE: Lazy<regex::Regex> =
Lazy::new(|| 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 5b46f4d

Please sign in to comment.