Skip to content

Commit 9d5410b

Browse files
author
andrew
committed
Replace static_init with OnceLock
1 parent 6db08fd commit 9d5410b

File tree

6 files changed

+18
-10
lines changed

6 files changed

+18
-10
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[workspace]
22
resolver = "2"
3-
members = ["crates/structre", "crates/structre_proc_macros"]
3+
members = ["crates/*"]
44

55
[workspace.package]
6-
version = "0.1.1"
6+
version = "0.1.2"
77
edition = "2021"
88
license = "ISC"
99
repository = "https://github.com/andrewbaxter/structre"

crates/structre/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ readme.workspace = true
99

1010
[dependencies]
1111
regex = { version = "1", default-features = false, features = ["std"] }
12-
static_init = "1"
13-
structre_proc_macros = { path = "../structre_proc_macros", version = "=0.1.1" }
12+
structre_proc_macros = { path = "../structre_proc_macros", version = "=0.1.2" }

crates/structre/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use {
55
};
66
pub use {
77
structre_proc_macros::structre,
8-
static_init,
98
regex,
109
};
1110

crates/structre_proc_macros/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,10 @@ fn gen_root(regex_span: Span, regex_raw: &str, ast: syn::DeriveInput) -> Result<
590590
type Err = structre::Error;
591591
fn from_str(input:& str) -> Result < #name,
592592
structre:: Error > {
593-
#[
594-
structre::static_init::dynamic
595-
] static RE: structre:: regex:: Regex = regex:: Regex:: new(#regex_raw).unwrap();
596-
let captures = RE.captures(input).ok_or(structre::Error::NoMatch)?;
593+
static RE: std::sync::OnceLock<structre::regex::Regex> = std::sync::OnceLock::new();
594+
let captures = RE.get_or_init(
595+
|| structre:: regex:: Regex:: new(#regex_raw).unwrap()
596+
).captures(input).ok_or(structre::Error::NoMatch) ?;
597597
#root
598598
}
599599
}

crates/structre_tests/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "structre_tests"
3+
publish = false
4+
5+
[dependencies]
6+
structre = { path = "../structre" }

crates/structre/tests/test.rs renamed to crates/structre_tests/tests/test.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
#![cfg(test)]
2+
3+
extern crate structre;
4+
15
use {
2-
structre::structre,
36
std::str::FromStr,
7+
structre::structre,
48
};
59

610
#[test]

0 commit comments

Comments
 (0)