From 1eedb8893935e8d2e8e7ee1ff27f6f2891319d2d Mon Sep 17 00:00:00 2001 From: edef Date: Wed, 8 May 2024 08:01:27 +0000 Subject: [PATCH] refactor(nix-compat/wire/bytes): style fixes Change-Id: I65c3c43df83e0c364a4b7f1f3054c5b676bd07d5 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11605 Reviewed-by: flokli Tested-by: BuildkiteCI --- tvix/nix-compat/src/wire/bytes/mod.rs | 23 ++++++++++------------- 1 file 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 161894f5f..db794b810 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: &mut R, allowed_size: RangeInclusive, -) -> std::io::Result> +) -> io::Result> 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: &mut R, - allowed_size: RangeInclusive, -) -> std::io::Result +pub async fn read_string(r: &mut R, allowed_size: RangeInclusive) -> io::Result where R: AsyncReadExt + Unpin, { @@ -107,7 +104,7 @@ where pub async fn write_bytes>( 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?;