From d15a7e20138934cc595107303488a6296d1af015 Mon Sep 17 00:00:00 2001 From: Yuanxin Cao <60498509+xx01cyx@users.noreply.github.com> Date: Sat, 9 Nov 2024 15:12:23 -0500 Subject: [PATCH] fix: use laze cell instead of lazy static (#25) --- optd-persistent/Cargo.lock | 1 - optd-persistent/Cargo.toml | 1 - optd-persistent/src/lib.rs | 27 +++++++++++++-------------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/optd-persistent/Cargo.lock b/optd-persistent/Cargo.lock index adf1584..3a8e5be 100644 --- a/optd-persistent/Cargo.lock +++ b/optd-persistent/Cargo.lock @@ -1146,7 +1146,6 @@ version = "0.1.0" dependencies = [ "async-stream", "async-trait", - "lazy_static", "sea-orm", "sea-orm-migration", "serde_json", diff --git a/optd-persistent/Cargo.toml b/optd-persistent/Cargo.toml index 55de4b7..e9b9905 100644 --- a/optd-persistent/Cargo.toml +++ b/optd-persistent/Cargo.toml @@ -21,4 +21,3 @@ trait-variant = "0.1.2" async-trait = "0.1.43" async-stream = "0.3.1" strum = "0.26.1" -lazy_static = "1" diff --git a/optd-persistent/src/lib.rs b/optd-persistent/src/lib.rs index 8f8a1d6..6158ef2 100644 --- a/optd-persistent/src/lib.rs +++ b/optd-persistent/src/lib.rs @@ -1,6 +1,6 @@ #![allow(dead_code)] -use std::sync::atomic::AtomicUsize; +use std::{cell::LazyCell, sync::atomic::AtomicUsize}; use sea_orm::*; use sea_orm_migration::prelude::*; @@ -17,19 +17,18 @@ pub const DATABASE_FILENAME: &str = "sqlite.db"; pub const DATABASE_URL: &str = "sqlite:./sqlite.db?mode=rwc"; pub const TEST_DATABASE_FILENAME: &str = "init.db"; -lazy_static::lazy_static! { - pub static ref TEST_DATABASE_FILE: String = { - std::env::current_dir().unwrap() - .join("src") - .join("db") - .join(TEST_DATABASE_FILENAME) - .to_str() - .unwrap() - .to_owned() - }; - pub static ref TEST_DATABASE_URL: String = - get_sqlite_url(TEST_DATABASE_FILE.as_str()); -} +pub const TEST_DATABASE_FILE: LazyCell = LazyCell::new(|| { + std::env::current_dir() + .unwrap() + .join("src") + .join("db") + .join(TEST_DATABASE_FILENAME) + .to_str() + .unwrap() + .to_owned() +}); +pub const TEST_DATABASE_URL: LazyCell = + LazyCell::new(|| get_sqlite_url(TEST_DATABASE_FILE.as_str())); fn get_sqlite_url(file: &str) -> String { format!("sqlite:{}?mode=rwc", file)