diff --git a/refinery_core/Cargo.toml b/refinery_core/Cargo.toml index ed43f595..e32f4325 100644 --- a/refinery_core/Cargo.toml +++ b/refinery_core/Cargo.toml @@ -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" diff --git a/refinery_core/src/runner.rs b/refinery_core/src/runner.rs index 80319659..76c7793b 100644 --- a/refinery_core/src/runner.rs +++ b/refinery_core/src/runner.rs @@ -1,4 +1,3 @@ -use once_cell::sync::Lazy; use regex::Regex; use siphasher::sip::SipHasher13; use time::OffsetDateTime; @@ -6,6 +5,7 @@ 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; @@ -13,12 +13,11 @@ 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 = OnceLock::new(); + RE.get_or_init(|| Regex::new(r"^([U|V])(\d+(?:\.\d+)?)__(\w+)").unwrap()) } -pub(crate) static RE: Lazy = Lazy::new(file_match_re); - /// An enum set that represents the type of the Migration #[derive(Clone, PartialEq)] pub enum Type { @@ -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 { - let captures = RE + let captures = file_match_re() .captures(input_name) .filter(|caps| caps.len() == 4) .ok_or_else(|| Error::new(Kind::InvalidName, None))?; diff --git a/refinery_core/src/util.rs b/refinery_core/src/util.rs index cdc58c8f..5992aab3 100644 --- a/refinery_core/src/util.rs +++ b/refinery_core/src/util.rs @@ -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 = - 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 {