diff --git a/channels/src/receiver.rs b/channels/src/receiver.rs index 31cdd46..95b5979 100644 --- a/channels/src/receiver.rs +++ b/channels/src/receiver.rs @@ -270,6 +270,21 @@ where } } +impl Receiver +where + D: Deserializer, +{ + #[inline] + fn deserialize_t( + &mut self, + data: &mut [u8], + ) -> Result> { + self.deserializer + .deserialize(data) + .map_err(RecvError::Serde) + } +} + impl Receiver where R: AsyncRead, @@ -301,9 +316,7 @@ where ) .await?; - self.deserializer - .deserialize(&mut payload) - .map_err(RecvError::Serde) + self.deserialize_t(&mut payload) } } @@ -341,9 +354,7 @@ where &mut self.reader, )?; - self.deserializer - .deserialize(&mut payload) - .map_err(RecvError::Serde) + self.deserialize_t(&mut payload) } } diff --git a/channels/src/sender.rs b/channels/src/sender.rs index 3e0065d..d8df2fc 100644 --- a/channels/src/sender.rs +++ b/channels/src/sender.rs @@ -231,6 +231,19 @@ where } } +impl Sender +where + S: Serializer, +{ + #[inline] + fn serialize_t( + &mut self, + t: &T, + ) -> Result, SendError> { + self.serializer.serialize(t).map_err(SendError::Serde) + } +} + impl Sender where W: AsyncWrite, @@ -262,10 +275,7 @@ where where D: Borrow, { - let payload = self - .serializer - .serialize(data.borrow()) - .map_err(SendError::Serde)?; + let payload = self.serialize_t(data.borrow())?; crate::protocol::send_async( &self.config, @@ -314,10 +324,7 @@ where where D: Borrow, { - let payload = self - .serializer - .serialize(data.borrow()) - .map_err(SendError::Serde)?; + let payload = self.serialize_t(data.borrow())?; crate::protocol::send_sync( &self.config,