From 6a86e902358480e61c410bc51610c34436ae2253 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Wed, 28 Jun 2023 11:44:40 +0200 Subject: [PATCH] feat: remove not required `Send` bound The async traits don't actually require the use of the `Send` bound. This is required for us to make use of them in a wasm context, where we explicitly have `!Send` readers and writers. --- src/reader.rs | 12 ++++++------ src/writer.rs | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/reader.rs b/src/reader.rs index 7a066c3..71e440c 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -25,7 +25,7 @@ pub trait VarIntReader { #[cfg(any(feature = "tokio_async", feature = "futures_async"))] /// Like a VarIntReader, but returns a future. -#[async_trait::async_trait] +#[async_trait::async_trait(?Send)] pub trait VarIntAsyncReader { async fn read_varint_async(&mut self) -> Result; } @@ -65,8 +65,8 @@ impl VarIntProcessor { } #[cfg(any(feature = "tokio_async", feature = "futures_async"))] -#[async_trait::async_trait] -impl VarIntAsyncReader for AR { +#[async_trait::async_trait(?Send)] +impl VarIntAsyncReader for AR { async fn read_varint_async(&mut self) -> Result { let mut buf = [0 as u8; 1]; let mut p = VarIntProcessor::new::(); @@ -124,14 +124,14 @@ pub trait FixedIntReader { /// Like FixedIntReader, but returns a future. #[cfg(any(feature = "tokio_async", feature = "futures_async"))] -#[async_trait::async_trait] +#[async_trait::async_trait(?Send)] pub trait FixedIntAsyncReader { async fn read_fixedint_async(&mut self) -> Result; } #[cfg(any(feature = "tokio_async", feature = "futures_async"))] -#[async_trait::async_trait] -impl FixedIntAsyncReader for AR { +#[async_trait::async_trait(?Send)] +impl FixedIntAsyncReader for AR { async fn read_fixedint_async(&mut self) -> Result { let mut buf = [0 as u8; 8]; self.read_exact(&mut buf[0..std::mem::size_of::()]) diff --git a/src/writer.rs b/src/writer.rs index c2d2ff3..e7799ea 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -17,16 +17,16 @@ pub trait VarIntWriter { /// Like VarIntWriter, but asynchronous. #[cfg(any(feature = "tokio_async", feature = "futures_async"))] -#[async_trait::async_trait] +#[async_trait::async_trait(?Send)] pub trait VarIntAsyncWriter { /// Write a VarInt integer to an asynchronous writer. - async fn write_varint_async(&mut self, n: VI) -> Result; + async fn write_varint_async(&mut self, n: VI) -> Result; } #[cfg(any(feature = "tokio_async", feature = "futures_async"))] -#[async_trait::async_trait] -impl VarIntAsyncWriter for AW { - async fn write_varint_async(&mut self, n: VI) -> Result { +#[async_trait::async_trait(?Send)] +impl VarIntAsyncWriter for AW { + async fn write_varint_async(&mut self, n: VI) -> Result { let mut buf = [0 as u8; 10]; let b = n.encode_var(&mut buf); self.write_all(&buf[0..b]).await?; @@ -50,15 +50,15 @@ pub trait FixedIntWriter { } #[cfg(any(feature = "tokio_async", feature = "futures_async"))] -#[async_trait::async_trait] +#[async_trait::async_trait(?Send)] pub trait FixedIntAsyncWriter { - async fn write_fixedint_async(&mut self, n: FI) -> Result; + async fn write_fixedint_async(&mut self, n: FI) -> Result; } #[cfg(any(feature = "tokio_async", feature = "futures_async"))] -#[async_trait::async_trait] -impl FixedIntAsyncWriter for AW { - async fn write_fixedint_async(&mut self, n: FI) -> Result { +#[async_trait::async_trait(?Send)] +impl FixedIntAsyncWriter for AW { + async fn write_fixedint_async(&mut self, n: FI) -> Result { let mut buf = [0 as u8; 8]; n.encode_fixed(&mut buf[..std::mem::size_of::()]); self.write_all(&buf[..std::mem::size_of::()]).await?;