Skip to content

Commit d15a7e2

Browse files
authored
fix: use laze cell instead of lazy static (#25)
1 parent 359e28a commit d15a7e2

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

optd-persistent/Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

optd-persistent/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ trait-variant = "0.1.2"
2121
async-trait = "0.1.43"
2222
async-stream = "0.3.1"
2323
strum = "0.26.1"
24-
lazy_static = "1"

optd-persistent/src/lib.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(dead_code)]
22

3-
use std::sync::atomic::AtomicUsize;
3+
use std::{cell::LazyCell, sync::atomic::AtomicUsize};
44

55
use sea_orm::*;
66
use sea_orm_migration::prelude::*;
@@ -17,19 +17,18 @@ pub const DATABASE_FILENAME: &str = "sqlite.db";
1717
pub const DATABASE_URL: &str = "sqlite:./sqlite.db?mode=rwc";
1818

1919
pub const TEST_DATABASE_FILENAME: &str = "init.db";
20-
lazy_static::lazy_static! {
21-
pub static ref TEST_DATABASE_FILE: String = {
22-
std::env::current_dir().unwrap()
23-
.join("src")
24-
.join("db")
25-
.join(TEST_DATABASE_FILENAME)
26-
.to_str()
27-
.unwrap()
28-
.to_owned()
29-
};
30-
pub static ref TEST_DATABASE_URL: String =
31-
get_sqlite_url(TEST_DATABASE_FILE.as_str());
32-
}
20+
pub const TEST_DATABASE_FILE: LazyCell<String> = LazyCell::new(|| {
21+
std::env::current_dir()
22+
.unwrap()
23+
.join("src")
24+
.join("db")
25+
.join(TEST_DATABASE_FILENAME)
26+
.to_str()
27+
.unwrap()
28+
.to_owned()
29+
});
30+
pub const TEST_DATABASE_URL: LazyCell<String> =
31+
LazyCell::new(|| get_sqlite_url(TEST_DATABASE_FILE.as_str()));
3332

3433
fn get_sqlite_url(file: &str) -> String {
3534
format!("sqlite:{}?mode=rwc", file)

0 commit comments

Comments
 (0)