Skip to content

Commit cc901e3

Browse files
committed
Add Addr::as_bytes
1 parent 7cabb7e commit cc901e3

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to
99
### Added
1010

1111
- cosmwasm-std: Add `Timestamp::minus_seconds` and `::minus_nanos`.
12+
- cosmwasm-std: Add `Addr::as_bytes`
1213

1314
## [0.14.0] - 2021-05-03
1415

packages/std/src/addresses.rs

+14
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ impl Addr {
5252
pub fn as_str(&self) -> &str {
5353
self.0.as_str()
5454
}
55+
56+
#[inline]
57+
pub fn as_bytes(&self) -> &[u8] {
58+
self.0.as_bytes()
59+
}
5560
}
5661

5762
impl fmt::Display for Addr {
@@ -287,6 +292,15 @@ mod tests {
287292
assert_eq!(addr.as_str(), "literal-string");
288293
}
289294

295+
#[test]
296+
fn addr_as_bytes_works() {
297+
let addr = Addr::unchecked("literal-string");
298+
assert_eq!(
299+
addr.as_bytes(),
300+
[108, 105, 116, 101, 114, 97, 108, 45, 115, 116, 114, 105, 110, 103]
301+
);
302+
}
303+
290304
#[test]
291305
fn addr_implements_display() {
292306
let addr = Addr::unchecked("cos934gh9034hg04g0h134");

0 commit comments

Comments
 (0)