Migrate from lazy_static to once_cell

This commit is contained in:
James Liu 2022-06-08 11:50:26 -07:00 committed by GitHub
parent 4c39b3188c
commit 2c01e9e747
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 477 additions and 519 deletions

View file

@ -46,6 +46,7 @@ use objc::{
rc::autoreleasepool,
runtime::{Class, Object, Sel, BOOL, NO, YES},
};
use once_cell::sync::Lazy;
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct WindowId(pub usize);
@ -246,32 +247,30 @@ struct WindowClass(*const Class);
unsafe impl Send for WindowClass {}
unsafe impl Sync for WindowClass {}
lazy_static! {
static ref WINDOW_CLASS: WindowClass = unsafe {
let window_superclass = class!(NSWindow);
let mut decl = ClassDecl::new("WinitWindow", window_superclass).unwrap();
static WINDOW_CLASS: Lazy<WindowClass> = Lazy::new(|| unsafe {
let window_superclass = class!(NSWindow);
let mut decl = ClassDecl::new("WinitWindow", window_superclass).unwrap();
pub extern "C" fn can_become_main_window(_: &Object, _: Sel) -> BOOL {
trace_scope!("canBecomeMainWindow");
YES
}
pub extern "C" fn can_become_main_window(_: &Object, _: Sel) -> BOOL {
trace_scope!("canBecomeMainWindow");
YES
}
pub extern "C" fn can_become_key_window(_: &Object, _: Sel) -> BOOL {
trace_scope!("canBecomeKeyWindow");
YES
}
pub extern "C" fn can_become_key_window(_: &Object, _: Sel) -> BOOL {
trace_scope!("canBecomeKeyWindow");
YES
}
decl.add_method(
sel!(canBecomeMainWindow),
can_become_main_window as extern "C" fn(&Object, Sel) -> BOOL,
);
decl.add_method(
sel!(canBecomeKeyWindow),
can_become_key_window as extern "C" fn(&Object, Sel) -> BOOL,
);
WindowClass(decl.register())
};
}
decl.add_method(
sel!(canBecomeMainWindow),
can_become_main_window as extern "C" fn(&Object, Sel) -> BOOL,
);
decl.add_method(
sel!(canBecomeKeyWindow),
can_become_key_window as extern "C" fn(&Object, Sel) -> BOOL,
);
WindowClass(decl.register())
});
#[derive(Default)]
pub struct SharedState {