about summary refs log tree commit diff
path: root/tvix/nix-compat/src/wire/bytes/mod.rs
diff options
context:
space:
mode:
authoredef <edef@edef.eu>2024-05-08T08·01+0000
committeredef <edef@edef.eu>2024-05-08T08·48+0000
commit1eedb8893935e8d2e8e7ee1ff27f6f2891319d2d (patch)
tree94c736e2bede693fecb2a0a0fd01ea8f1cd86db8 /tvix/nix-compat/src/wire/bytes/mod.rs
parentca10a8726f2c777888f38fc267de845bfa7eab5d (diff)
refactor(nix-compat/wire/bytes): style fixes r/8088
Change-Id: I65c3c43df83e0c364a4b7f1f3054c5b676bd07d5
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11605
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/nix-compat/src/wire/bytes/mod.rs')
-rw-r--r--tvix/nix-compat/src/wire/bytes/mod.rs23
1 files changed, 10 insertions, 13 deletions
diff --git a/tvix/nix-compat/src/wire/bytes/mod.rs b/tvix/nix-compat/src/wire/bytes/mod.rs
index 161894f5f749..db794b810f35 100644
--- a/tvix/nix-compat/src/wire/bytes/mod.rs
+++ b/tvix/nix-compat/src/wire/bytes/mod.rs
@@ -2,7 +2,7 @@ use std::{
     io::{Error, ErrorKind},
     ops::RangeInclusive,
 };
-use tokio::io::{AsyncReadExt, AsyncWriteExt};
+use tokio::io::{self, AsyncReadExt, AsyncWriteExt};
 
 pub(crate) mod reader;
 pub use reader::BytesReader;
@@ -35,7 +35,7 @@ const LEN_SIZE: usize = 8;
 pub async fn read_bytes<R: ?Sized>(
     r: &mut R,
     allowed_size: RangeInclusive<usize>,
-) -> std::io::Result<Vec<u8>>
+) -> io::Result<Vec<u8>>
 where
     R: AsyncReadExt + Unpin,
 {
@@ -46,8 +46,8 @@ where
         .ok()
         .filter(|len| allowed_size.contains(len))
         .ok_or_else(|| {
-            std::io::Error::new(
-                std::io::ErrorKind::InvalidData,
+            io::Error::new(
+                io::ErrorKind::InvalidData,
                 "signalled package size not in allowed range",
             )
         })?;
@@ -63,15 +63,15 @@ where
 
     // make sure we got exactly the number of bytes, and not less.
     if s as u64 != padded_len {
-        return Err(std::io::ErrorKind::UnexpectedEof.into());
+        return Err(io::ErrorKind::UnexpectedEof.into());
     }
 
     let (_content, padding) = buf.split_at(len);
 
     // ensure the padding is all zeroes.
-    if !padding.iter().all(|e| *e == b'\0') {
-        return Err(std::io::Error::new(
-            std::io::ErrorKind::InvalidData,
+    if padding.iter().any(|&b| b != 0) {
+        return Err(io::Error::new(
+            io::ErrorKind::InvalidData,
             "padding is not all zeroes",
         ));
     }
@@ -84,10 +84,7 @@ where
 /// Read a "bytes wire packet" of from the AsyncRead and tries to parse as string.
 /// Internally uses [read_bytes].
 /// Rejects reading more than `allowed_size` bytes of payload.
-pub async fn read_string<R>(
-    r: &mut R,
-    allowed_size: RangeInclusive<usize>,
-) -> std::io::Result<String>
+pub async fn read_string<R>(r: &mut R, allowed_size: RangeInclusive<usize>) -> io::Result<String>
 where
     R: AsyncReadExt + Unpin,
 {
@@ -107,7 +104,7 @@ where
 pub async fn write_bytes<W: AsyncWriteExt + Unpin, B: AsRef<[u8]>>(
     w: &mut W,
     b: B,
-) -> std::io::Result<()> {
+) -> io::Result<()> {
     // write the size packet.
     w.write_u64_le(b.as_ref().len() as u64).await?;