about summary refs log tree commit diff
path: root/tvix/nix-compat/src/wire
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2024-10-13T10·19+0300
committerclbot <clbot@tvl.fyi>2024-10-13T14·31+0000
commit5faf7c9d7b5fcf8fb2795b5879aece45d7c62b21 (patch)
tree4ccc1959a7ee0047f4724ccd0ff7e60a7b166c9c /tvix/nix-compat/src/wire
parentcb032b250e7b46ebc28038c8efb48f6a9c0ac75b (diff)
refactor(tvix/nix-compat): remove use of lazy_static r/8802
This is now supported in the standard library via std::sync::LazyLock, but
requires some manual shuffling around of code.

I found at least one dead variable along the way, which I deleted.

Change-Id: I8600c87c49078fb5ff72671994c77b919259e67b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12608
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Autosubmit: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix/nix-compat/src/wire')
-rw-r--r--tvix/nix-compat/src/wire/bytes/reader/mod.rs7
-rw-r--r--tvix/nix-compat/src/wire/bytes/writer.rs7
2 files changed, 6 insertions, 8 deletions
diff --git a/tvix/nix-compat/src/wire/bytes/reader/mod.rs b/tvix/nix-compat/src/wire/bytes/reader/mod.rs
index 77950496ed6b..a6209a6e6dad 100644
--- a/tvix/nix-compat/src/wire/bytes/reader/mod.rs
+++ b/tvix/nix-compat/src/wire/bytes/reader/mod.rs
@@ -299,11 +299,11 @@ fn with_limited<R>(buf: &mut ReadBuf, n: u64, f: impl FnOnce(&mut ReadBuf) -> R)
 
 #[cfg(test)]
 mod tests {
+    use std::sync::LazyLock;
     use std::time::Duration;
 
     use crate::wire::bytes::{padding_len, write_bytes};
     use hex_literal::hex;
-    use lazy_static::lazy_static;
     use rstest::rstest;
     use tokio::io::{AsyncReadExt, BufReader};
     use tokio_test::io::Builder;
@@ -314,9 +314,8 @@ mod tests {
     /// cases.
     const MAX_LEN: u64 = 1024;
 
-    lazy_static! {
-        pub static ref LARGE_PAYLOAD: Vec<u8> = (0..255).collect::<Vec<u8>>().repeat(4 * 1024);
-    }
+    pub static LARGE_PAYLOAD: LazyLock<Vec<u8>> =
+        LazyLock::new(|| (0..255).collect::<Vec<u8>>().repeat(4 * 1024));
 
     /// Helper function, calling the (simpler) write_bytes with the payload.
     /// We use this to create data we want to read from the wire.
diff --git a/tvix/nix-compat/src/wire/bytes/writer.rs b/tvix/nix-compat/src/wire/bytes/writer.rs
index f5632771e961..8b9b59aa1b85 100644
--- a/tvix/nix-compat/src/wire/bytes/writer.rs
+++ b/tvix/nix-compat/src/wire/bytes/writer.rs
@@ -232,19 +232,18 @@ where
 
 #[cfg(test)]
 mod tests {
+    use std::sync::LazyLock;
     use std::time::Duration;
 
     use crate::wire::bytes::write_bytes;
     use hex_literal::hex;
-    use lazy_static::lazy_static;
     use tokio::io::AsyncWriteExt;
     use tokio_test::{assert_err, assert_ok, io::Builder};
 
     use super::*;
 
-    lazy_static! {
-        pub static ref LARGE_PAYLOAD: Vec<u8> = (0..255).collect::<Vec<u8>>().repeat(4 * 1024);
-    }
+    pub static LARGE_PAYLOAD: LazyLock<Vec<u8>> =
+        LazyLock::new(|| (0..255).collect::<Vec<u8>>().repeat(4 * 1024));
 
     /// Helper function, calling the (simpler) write_bytes with the payload.
     /// We use this to create data we want to see on the wire.