From ded0176486d556b9eb9d32ba42135f82a5691765 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 18 May 2021 15:45:20 +1000 Subject: [PATCH] Rename function as per Rust naming convention Functions that allocate should start with `to_`. `as_` is used for cheap conversions. --- src/util/address.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/util/address.rs b/src/util/address.rs index 67e798f1..103ecc5c 100644 --- a/src/util/address.rs +++ b/src/util/address.rs @@ -248,7 +248,7 @@ impl Address { } /// Serialize the address as a vector of bytes. - pub fn as_bytes(&self) -> Vec { + pub fn to_bytes(&self) -> Vec { 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()); @@ -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()) } } @@ -402,7 +402,7 @@ 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] @@ -410,7 +410,7 @@ mod tests { 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]