Skip to content

Commit

Permalink
Rename function as per Rust naming convention
Browse files Browse the repository at this point in the history
Functions that allocate should start with `to_`. `as_` is used for
cheap conversions.
  • Loading branch information
thomaseizinger committed May 19, 2021
1 parent 65f8786 commit ded0176
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/util/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl Address {
}

/// Serialize the address as a vector of bytes.
pub fn as_bytes(&self) -> Vec<u8> {
pub fn to_bytes(&self) -> Vec<u8> {
let mut bytes = vec![self.network.as_u8(&self.addr_type)];
bytes.extend_from_slice(self.public_spend.as_bytes());
bytes.extend_from_slice(self.public_view.as_bytes());
Expand All @@ -264,13 +264,13 @@ impl Address {

/// Serialize the address as an hexadecimal string.
pub fn as_hex(&self) -> String {
hex::encode(self.as_bytes())
hex::encode(self.to_bytes())
}
}

impl fmt::Display for Address {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", base58::encode(self.as_bytes().as_slice()).unwrap())
write!(f, "{}", base58::encode(self.to_bytes().as_slice()).unwrap())
}
}

Expand Down Expand Up @@ -402,15 +402,15 @@ mod tests {
let address = "4ADT1BtbxqEWeMKp9GgPr2NeyJXXtNxvoDawpyA4WpzFcGcoHUvXeijE66DNfohE9r1bQYaBiQjEtKE7CtkTdLwiDznFzra";
let add = Address::from_str(address).unwrap();
let bytes = base58::decode(address).unwrap();
assert_eq!(bytes, add.as_bytes());
assert_eq!(bytes, add.to_bytes());
}

#[test]
fn serialize_integrated_address() {
let address = "4Byr22j9M2878Mtyb3fEPcBNwBZf5EXqn1Yi6VzR46618SFBrYysab2Cs1474CVDbsh94AJq7vuV3Z2DRq4zLcY3LHzo1Nbv3d8J6VhvCV";
let add = Address::from_str(address).unwrap();
let bytes = base58::decode(address).unwrap();
assert_eq!(bytes, add.as_bytes());
assert_eq!(bytes, add.to_bytes());
}

#[test]
Expand Down

0 comments on commit ded0176

Please sign in to comment.