Skip to content

Commit

Permalink
fix(rs-transport): hash only resource repr
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Volosatovs <[email protected]>
  • Loading branch information
rvolosatovs committed Aug 2, 2024
1 parent 495b6d6 commit d775648
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/transport/src/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 13 additions & 3 deletions crates/transport/src/value.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -32,7 +32,6 @@ use wasm_tokio::{
Leb128Encoder, Utf8Codec,
};

#[derive(Hash)]
#[repr(transparent)]
pub struct ResourceBorrow<T: ?Sized> {
repr: Bytes,
Expand Down Expand Up @@ -71,6 +70,12 @@ impl<T: ?Sized> PartialEq for ResourceBorrow<T> {

impl<T: ?Sized> Eq for ResourceBorrow<T> {}

impl<T: ?Sized> Hash for ResourceBorrow<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.repr.hash(state)
}
}

impl<T: ?Sized> AsRef<[u8]> for ResourceBorrow<T> {
fn as_ref(&self) -> &[u8] {
&self.repr
Expand All @@ -95,7 +100,6 @@ impl<T: ?Sized> ResourceBorrow<T> {
}
}

#[derive(Hash)]
#[repr(transparent)]
pub struct ResourceOwn<T: ?Sized> {
repr: Bytes,
Expand Down Expand Up @@ -143,6 +147,12 @@ impl<T: ?Sized> PartialEq for ResourceOwn<T> {

impl<T: ?Sized> Eq for ResourceOwn<T> {}

impl<T: ?Sized> Hash for ResourceOwn<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.repr.hash(state)
}
}

impl<T: ?Sized> AsRef<[u8]> for ResourceOwn<T> {
fn as_ref(&self) -> &[u8] {
&self.repr
Expand Down

0 comments on commit d775648

Please sign in to comment.