From d775648e6c9a2b452a98ad76cafa0257d8122621 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Fri, 2 Aug 2024 18:58:15 +0200 Subject: [PATCH] fix(rs-transport): hash only resource repr Signed-off-by: Roman Volosatovs --- crates/transport/src/invoke.rs | 2 +- crates/transport/src/value.rs | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/crates/transport/src/invoke.rs b/crates/transport/src/invoke.rs index 13a5b5b9..c236b234 100644 --- a/crates/transport/src/invoke.rs +++ b/crates/transport/src/invoke.rs @@ -283,7 +283,7 @@ pub trait InvokeExt: Invoke { } /// Returns a [`Timeout`], wrapping [Self] with an implementation of [Invoke], which will - /// error, if call to [Self::invoke] does not return within a supplied `timeout` + /// error, if call to [`Self::invoke`] does not return within a supplied `timeout` fn timeout(&self, timeout: Duration) -> Timeout<'_, Self> { Timeout { inner: self, diff --git a/crates/transport/src/value.rs b/crates/transport/src/value.rs index 68fbf6ac..45962b91 100644 --- a/crates/transport/src/value.rs +++ b/crates/transport/src/value.rs @@ -1,7 +1,7 @@ use core::any::TypeId; use core::fmt::{self, Debug}; use core::future::Future; -use core::hash::Hash; +use core::hash::{Hash, Hasher}; use core::iter::zip; use core::marker::PhantomData; use core::mem; @@ -32,7 +32,6 @@ use wasm_tokio::{ Leb128Encoder, Utf8Codec, }; -#[derive(Hash)] #[repr(transparent)] pub struct ResourceBorrow { repr: Bytes, @@ -71,6 +70,12 @@ impl PartialEq for ResourceBorrow { impl Eq for ResourceBorrow {} +impl Hash for ResourceBorrow { + fn hash(&self, state: &mut H) { + self.repr.hash(state) + } +} + impl AsRef<[u8]> for ResourceBorrow { fn as_ref(&self) -> &[u8] { &self.repr @@ -95,7 +100,6 @@ impl ResourceBorrow { } } -#[derive(Hash)] #[repr(transparent)] pub struct ResourceOwn { repr: Bytes, @@ -143,6 +147,12 @@ impl PartialEq for ResourceOwn { impl Eq for ResourceOwn {} +impl Hash for ResourceOwn { + fn hash(&self, state: &mut H) { + self.repr.hash(state) + } +} + impl AsRef<[u8]> for ResourceOwn { fn as_ref(&self) -> &[u8] { &self.repr