From c646bf7890f88636c5df0e9b5a7369c55c3dce4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Leegwater=20Sim=C3=B5es?= Date: Mon, 29 Jul 2024 23:33:43 +0200 Subject: [PATCH] uplink: add `impl PartialEq<[u8; 32]> for ContractId` According to the cross crate considerations* of the Rust documentation, one should only implement `PartialEq` for local types, and not for foreign types. As for implementing it on references... `PartialEq` already takes both operands by reference, making these implementations useless in practice. * https://doc.rust-lang.org/std/cmp/trait.PartialEq.html#cross-crate-considerations Resolves: #375 --- piecrust-uplink/CHANGELOG.md | 5 +++++ piecrust-uplink/src/types.rs | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/piecrust-uplink/CHANGELOG.md b/piecrust-uplink/CHANGELOG.md index d704ee72..d07339ce 100644 --- a/piecrust-uplink/CHANGELOG.md +++ b/piecrust-uplink/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Add `impl PartialEq<[u8; 32]> for ContractId` [#375] + ## [0.15.0] - 2024-07-03 ### Fixed @@ -188,6 +192,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - First `piecrust-uplink` release +[#375]: https://github.com/dusk-network/piecrust/issues/375 [#365]: https://github.com/dusk-network/piecrust/issues/365 [#357]: https://github.com/dusk-network/piecrust/issues/357 [#353]: https://github.com/dusk-network/piecrust/issues/353 diff --git a/piecrust-uplink/src/types.rs b/piecrust-uplink/src/types.rs index 50c1c6c7..81ce1aa8 100644 --- a/piecrust-uplink/src/types.rs +++ b/piecrust-uplink/src/types.rs @@ -117,6 +117,12 @@ impl AsMut<[u8]> for ContractId { } } +impl PartialEq<[u8; CONTRACT_ID_BYTES]> for ContractId { + fn eq(&self, other: &[u8; CONTRACT_ID_BYTES]) -> bool { + self.0.eq(other) + } +} + impl core::fmt::Debug for ContractId { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { core::fmt::Display::fmt(self, f)