Skip to content

Commit

Permalink
Implement PartialEq between Addr and &Addr
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Apr 21, 2023
1 parent 8f99179 commit e99f082
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to
- cosmwasm-vm: Add `Cache::save_wasm_unchecked` to save Wasm blobs that have
been checked before. This is useful for state-sync where we know the Wasm code
was checked when it was first uploaded. ([#1635])
- cosmwasm-std: Implement `PartialEq` for `Addr == &Addr` and `&Addr == Addr`.

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

Expand Down
25 changes: 25 additions & 0 deletions packages/std/src/addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ impl AsRef<str> for Addr {
}
}

/// Implement `Addr == &Addr`
impl PartialEq<&Addr> for Addr {
fn eq(&self, rhs: &&Addr) -> bool {
self == *rhs
}
}

/// Implement `&Addr == Addr`
impl PartialEq<Addr> for &Addr {
fn eq(&self, rhs: &Addr) -> bool {
self == rhs
}
}

/// Implement `Addr == &str`
///
/// Deprecated. This comparison unsafe. Convert both sides to Addr first.
Expand Down Expand Up @@ -457,6 +471,17 @@ mod tests {
assert_eq!(String::from("cos934gh9034hg04g0h134"), addr);
}

#[test]
fn addr_implements_partial_eq_addr_ref() {
let addr = Addr::unchecked("cos934gh9034hg04g0h134");
let addr_ref = &addr;

// `Addr == &Addr`
assert_eq!(addr, addr_ref);
// `&Addr == Addr`
assert_eq!(addr_ref, addr);
}

#[test]
fn addr_implements_into_string() {
// owned Addr
Expand Down

0 comments on commit e99f082

Please sign in to comment.