mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-25 09:39:52 +08:00
Use once_cell instead of lazy_static
lazy_static has better ergonomics at the call/access sites (it returns a reference to the type directly, whereas with once_cell we get a static Lazy<T> that we must dereference instead) but the once_cell api is slated for integration into the standard library [0] and has been the "preferred" way to declare static global variables w/ deferred initialization. It's also less opaque and easier to comprehend how it works, I guess? (Both `once_cell` and `lazy_static` are already in our dependency tree, so this should have no detrimental effect on build times. It actually negligibly *improves* build times by not using macros, reducing the amount of expansion the compiler has to do by a miniscule amount.) [0]: https://github.com/rust-lang/rust/issues/74465
This commit is contained in:
parent
39c3faeaf4
commit
d7febd4f3e
1
fish-rust/Cargo.lock
generated
1
fish-rust/Cargo.lock
generated
|
@ -358,6 +358,7 @@ dependencies = [
|
||||||
"miette",
|
"miette",
|
||||||
"nix",
|
"nix",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
|
"once_cell",
|
||||||
"unixstring",
|
"unixstring",
|
||||||
"widestring",
|
"widestring",
|
||||||
"widestring-suffix",
|
"widestring-suffix",
|
||||||
|
|
|
@ -15,6 +15,7 @@ lazy_static = "1.4.0"
|
||||||
libc = "0.2.137"
|
libc = "0.2.137"
|
||||||
nix = { version = "0.25.0", default-features = false, features = [] }
|
nix = { version = "0.25.0", default-features = false, features = [] }
|
||||||
num-traits = "0.2.15"
|
num-traits = "0.2.15"
|
||||||
|
once_cell = "1.17.0"
|
||||||
unixstring = "0.2.7"
|
unixstring = "0.2.7"
|
||||||
widestring = "1.0.2"
|
widestring = "1.0.2"
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,6 @@
|
||||||
#![allow(clippy::needless_return)]
|
#![allow(clippy::needless_return)]
|
||||||
#![allow(clippy::manual_is_ascii_check)]
|
#![allow(clippy::manual_is_ascii_check)]
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate lazy_static;
|
|
||||||
|
|
||||||
mod fd_readable_set;
|
mod fd_readable_set;
|
||||||
mod fds;
|
mod fds;
|
||||||
#[allow(rustdoc::broken_intra_doc_links)]
|
#[allow(rustdoc::broken_intra_doc_links)]
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
use crate::ffi;
|
use crate::ffi;
|
||||||
pub use cxx::CxxWString;
|
pub use cxx::CxxWString;
|
||||||
pub use ffi::{wchar_t, wcharz_t};
|
pub use ffi::{wchar_t, wcharz_t};
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
pub use widestring::U32CString as W0String;
|
pub use widestring::U32CString as W0String;
|
||||||
pub use widestring::{u32cstr, utf32str};
|
pub use widestring::{u32cstr, utf32str};
|
||||||
pub use widestring::{Utf32Str as wstr, Utf32String as WString};
|
pub use widestring::{Utf32Str as wstr, Utf32String as WString};
|
||||||
|
@ -72,14 +73,12 @@ macro_rules! wcharz {
|
||||||
pub(crate) use c_str;
|
pub(crate) use c_str;
|
||||||
pub(crate) use wcharz;
|
pub(crate) use wcharz;
|
||||||
|
|
||||||
lazy_static! {
|
static EMPTY_WSTRING: Lazy<cxx::UniquePtr<cxx::CxxWString>> =
|
||||||
/// A shared, empty CxxWString.
|
Lazy::new(|| cxx::CxxWString::create(&[]));
|
||||||
static ref EMPTY_WSTRING: cxx::UniquePtr<cxx::CxxWString> = cxx::CxxWString::create(&[]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \return a reference to a shared empty wstring.
|
/// \return a reference to a shared empty wstring.
|
||||||
pub fn empty_wstring() -> &'static cxx::CxxWString {
|
pub fn empty_wstring() -> &'static cxx::CxxWString {
|
||||||
&EMPTY_WSTRING
|
&*EMPTY_WSTRING
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implement Debug for wcharz_t.
|
/// Implement Debug for wcharz_t.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user