Cleanup both size functions

This commit is contained in:
Abhishek Chanda
2023-04-06 21:03:29 -05:00
committed by Abhishek Chanda
parent a96f30d64e
commit ec79428c75
2 changed files with 3 additions and 4 deletions

View File

@ -215,9 +215,8 @@ impl Ipv4Network {
/// assert_eq!(tinynet.size(), 1); /// assert_eq!(tinynet.size(), 1);
/// ``` /// ```
pub fn size(self) -> u32 { pub fn size(self) -> u32 {
let host_bits = u32::from(IPV4_BITS - self.prefix); 1 << (u32::from(IPV4_BITS - self.prefix))
(2 as u32).pow(host_bits) }
}
/// Returns the `n`:th address within this network. /// Returns the `n`:th address within this network.
/// The adresses are indexed from 0 and `n` must be smaller than the size of the network. /// The adresses are indexed from 0 and `n` must be smaller than the size of the network.

View File

@ -242,7 +242,7 @@ impl Ipv6Network {
/// ``` /// ```
pub fn size(&self) -> u128 { pub fn size(&self) -> u128 {
let host_bits = u32::from(IPV6_BITS - self.prefix); let host_bits = u32::from(IPV6_BITS - self.prefix);
(2 as u128).pow(host_bits) 2u128.pow(host_bits)
} }
} }