Skip to content

Commit

Permalink
Replace lazy_static with better equivalent
Browse files Browse the repository at this point in the history
Summary:
Preference order:

- `const`
- `std::sync::OnceLock`
- `std::sync::LazyLock` if already is using unstable features or if it's
  a package that has no hope of ever building with cargo.
- `once_cell::sync::Lazy` as a last resort (since this is easy to
  codemod to `std::sync::LazyLock` when that's stable).

Reviewed By: dtolnay

Differential Revision: D49988865

fbshipit-source-id: 51b916aaba4bae32e3f415bbf8c7ceedb36c5e11
  • Loading branch information
zertosh authored and facebook-github-bot committed Oct 6, 2023
1 parent b2292d5 commit 1ba8f67
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion common/rust/shed/hostcaps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ name = "test_hostcaps"
path = "src/bin/test.rs"

[dependencies]
lazy_static = "1.4"
once_cell = "1.12"

[features]
default = []
Expand Down
11 changes: 5 additions & 6 deletions common/rust/shed/hostcaps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* of this source tree.
*/

use lazy_static::lazy_static;
use once_cell::sync::Lazy;

#[cfg(any(fbcode_build, feature = "fb"))]
mod facebook;
#[cfg(any(fbcode_build, feature = "fb"))]
Expand All @@ -21,11 +22,9 @@ pub use facebook::is_prod;
#[cfg(any(fbcode_build, feature = "fb"))]
pub use facebook::Env;

lazy_static! {
pub static ref IN_PROD: bool = is_prod();
pub static ref IN_CORP: bool = is_corp();
pub static ref IN_LAB: bool = is_lab();
}
pub static IN_PROD: Lazy<bool> = Lazy::new(is_prod);
pub static IN_CORP: Lazy<bool> = Lazy::new(is_corp);
pub static IN_LAB: Lazy<bool> = Lazy::new(is_lab);

#[cfg(not(any(fbcode_build, feature = "fb")))]
pub fn get_env() -> u8 {
Expand Down

0 comments on commit 1ba8f67

Please sign in to comment.