diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-08-10 19:06:46 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-08-10 19:06:46 +0200 |
| commit | 63cfcbe7a7745b276de58ec92e0141b958c44feb (patch) | |
| tree | 990e33a83756e27187033579ee2f85d5c79169d5 /src/config/mod.rs | |
| parent | b747ca8af52129876b577a4f20f7105a05c6b002 (diff) | |
use unsafe blocks instead of mutexes
Diffstat (limited to 'src/config/mod.rs')
| -rw-r--r-- | src/config/mod.rs | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs index cc4154c..4aac0cf 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,11 +1,10 @@ -use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; +use std::ptr::addr_of_mut; -use lazy_static::lazy_static; use mlua::{UserData, UserDataFields}; use self::{keymap::KeyMap, theme::Theme}; -pub mod constants; +pub mod env; pub mod theme; pub mod keymap; @@ -15,10 +14,6 @@ pub struct GlobalConfig { pub keymap: KeyMap, } -lazy_static! { - static ref GLOBAL_CONFIG: RwLock<GlobalConfig> = RwLock::new(GlobalConfig::new()); -} - const DUMMY_CONFIG: GlobalConfig = GlobalConfig::new(); impl GlobalConfig { @@ -29,12 +24,9 @@ impl GlobalConfig { } } - pub fn instance() -> RwLockReadGuard<'static, Self> { - GLOBAL_CONFIG.read().unwrap() - } - - pub fn instance_mut() -> RwLockWriteGuard<'static, Self> { - GLOBAL_CONFIG.write().unwrap() + pub fn get() -> &'static mut Self { + static mut GLOBAL_CONFIG: GlobalConfig = GlobalConfig::new(); + unsafe { &mut *addr_of_mut!(GLOBAL_CONFIG) } } } |