diff options
author | Florian Klink <flokli@flokli.de> | 2024-10-13T15·47+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-10-17T21·57+0000 |
commit | f0d594789ee01df43de50198adef91a11e2a355a (patch) | |
tree | 61433eed589427d500f824cef3053a62537d154c | |
parent | cdbdd2d04ecb2675f9c1d7ded7d99ad3a483b6fc (diff) |
refactor(tvix/castore): remove remaining lazy_static usage r/8824
Change-Id: I86480cf625a457c4aa8153262f829d34c230b084 Co-authored-by: edef <edef@edef.eu> Reviewed-on: https://cl.tvl.fyi/c/depot/+/12613 Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI Reviewed-by: edef <edef@edef.eu>
-rw-r--r-- | tvix/Cargo.lock | 1 | ||||
-rw-r--r-- | tvix/Cargo.nix | 4 | ||||
-rw-r--r-- | tvix/castore/Cargo.toml | 1 | ||||
-rw-r--r-- | tvix/castore/src/composition.rs | 18 |
4 files changed, 8 insertions, 16 deletions
diff --git a/tvix/Cargo.lock b/tvix/Cargo.lock index 5301c8d84a02..eb40901630af 100644 --- a/tvix/Cargo.lock +++ b/tvix/Cargo.lock @@ -4584,7 +4584,6 @@ dependencies = [ "futures", "hex-literal", "hyper-util", - "lazy_static", "libc", "object_store", "parking_lot", diff --git a/tvix/Cargo.nix b/tvix/Cargo.nix index 3dfe08ec7491..64afa81bdc92 100644 --- a/tvix/Cargo.nix +++ b/tvix/Cargo.nix @@ -15180,10 +15180,6 @@ rec { packageId = "hyper-util"; } { - name = "lazy_static"; - packageId = "lazy_static"; - } - { name = "libc"; packageId = "libc"; optional = true; diff --git a/tvix/castore/Cargo.toml b/tvix/castore/Cargo.toml index 5fdcba62febb..0799b471c34f 100644 --- a/tvix/castore/Cargo.toml +++ b/tvix/castore/Cargo.toml @@ -14,7 +14,6 @@ data-encoding = { workspace = true } digest = { workspace = true } fastcdc = { workspace = true, features = ["tokio"] } futures = { workspace = true } -lazy_static = { workspace = true } object_store = { workspace = true, features = ["http"] } parking_lot = { workspace = true } pin-project-lite = { workspace = true } diff --git a/tvix/castore/src/composition.rs b/tvix/castore/src/composition.rs index d52cc4060653..b251187e1c34 100644 --- a/tvix/castore/src/composition.rs +++ b/tvix/castore/src/composition.rs @@ -99,7 +99,6 @@ use erased_serde::deserialize; use futures::future::BoxFuture; use futures::FutureExt; -use lazy_static::lazy_static; use serde::de::DeserializeOwned; use serde_tagged::de::{BoxFnSeed, SeedFactory}; use serde_tagged::util::TagString; @@ -108,7 +107,7 @@ use std::cell::Cell; use std::collections::BTreeMap; use std::collections::HashMap; use std::marker::PhantomData; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; use tonic::async_trait; /// Resolves tag names to the corresponding Config type. @@ -261,14 +260,13 @@ pub fn with_registry<R>(reg: &'static Registry, f: impl FnOnce() -> R) -> R { result } -lazy_static! { - /// The provided registry of tvix_castore, with all builtin BlobStore/DirectoryStore implementations - pub static ref REG: Registry = { - let mut reg = Default::default(); - add_default_services(&mut reg); - reg - }; -} +/// The provided registry of tvix_castore, with all builtin BlobStore/DirectoryStore implementations +pub static REG: LazyLock<&'static Registry> = LazyLock::new(|| { + let mut reg = Default::default(); + add_default_services(&mut reg); + // explicitly leak to get an &'static, so that we gain `&Registry: Send` from `Registry: Sync` + Box::leak(Box::new(reg)) +}); // ---------- End of generic registry code --------- // |