Skip to content

Commit e99f082

Browse files
committed
Implement PartialEq between Addr and &Addr
1 parent 8f99179 commit e99f082

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to
1111
- cosmwasm-vm: Add `Cache::save_wasm_unchecked` to save Wasm blobs that have
1212
been checked before. This is useful for state-sync where we know the Wasm code
1313
was checked when it was first uploaded. ([#1635])
14+
- cosmwasm-std: Implement `PartialEq` for `Addr == &Addr` and `&Addr == Addr`.
1415

1516
[#1635]: https://github.com/CosmWasm/cosmwasm/pull/1635
1617

packages/std/src/addresses.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ impl AsRef<str> for Addr {
8585
}
8686
}
8787

88+
/// Implement `Addr == &Addr`
89+
impl PartialEq<&Addr> for Addr {
90+
fn eq(&self, rhs: &&Addr) -> bool {
91+
self == *rhs
92+
}
93+
}
94+
95+
/// Implement `&Addr == Addr`
96+
impl PartialEq<Addr> for &Addr {
97+
fn eq(&self, rhs: &Addr) -> bool {
98+
self == rhs
99+
}
100+
}
101+
88102
/// Implement `Addr == &str`
89103
///
90104
/// Deprecated. This comparison unsafe. Convert both sides to Addr first.
@@ -457,6 +471,17 @@ mod tests {
457471
assert_eq!(String::from("cos934gh9034hg04g0h134"), addr);
458472
}
459473

474+
#[test]
475+
fn addr_implements_partial_eq_addr_ref() {
476+
let addr = Addr::unchecked("cos934gh9034hg04g0h134");
477+
let addr_ref = &addr;
478+
479+
// `Addr == &Addr`
480+
assert_eq!(addr, addr_ref);
481+
// `&Addr == Addr`
482+
assert_eq!(addr_ref, addr);
483+
}
484+
460485
#[test]
461486
fn addr_implements_into_string() {
462487
// owned Addr

0 commit comments

Comments
 (0)