@@ -5,19 +5,17 @@ use time::OffsetDateTime;
5
5
use std:: cmp:: Ordering ;
6
6
use std:: fmt;
7
7
use std:: hash:: { Hash , Hasher } ;
8
+ use std:: sync:: OnceLock ;
8
9
9
10
use crate :: error:: Kind ;
10
11
use crate :: traits:: DEFAULT_MIGRATION_TABLE_NAME ;
11
12
use crate :: { AsyncMigrate , Error , Migrate } ;
12
13
use std:: fmt:: Formatter ;
13
14
14
15
// regex used to match file names
15
- pub fn file_match_re ( ) -> Regex {
16
- Regex :: new ( r"^([U|V])(\d+(?:\.\d+)?)__(\w+)" ) . unwrap ( )
17
- }
18
-
19
- lazy_static:: lazy_static! {
20
- static ref RE : regex:: Regex = file_match_re( ) ;
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 ( ) )
21
19
}
22
20
23
21
/// An enum set that represents the type of the Migration
@@ -84,7 +82,7 @@ impl Migration {
84
82
/// Create an unapplied migration, name and version are parsed from the input_name,
85
83
/// which must be named in the format (U|V){1}__{2}.rs where {1} represents the migration version and {2} the name.
86
84
pub fn unapplied ( input_name : & str , sql : & str ) -> Result < Migration , Error > {
87
- let captures = RE
85
+ let captures = file_match_re ( )
88
86
. captures ( input_name)
89
87
. filter ( |caps| caps. len ( ) == 4 )
90
88
. ok_or_else ( || Error :: new ( Kind :: InvalidName , None ) ) ?;
0 commit comments