From ec79428c7573917ee231fda9a63b864476780d56 Mon Sep 17 00:00:00 2001 From: Abhishek Chanda Date: Thu, 6 Apr 2023 21:03:29 -0500 Subject: [PATCH] Cleanup both size functions --- src/ipv4.rs | 5 ++--- src/ipv6.rs | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ipv4.rs b/src/ipv4.rs index d162fb6..00e7b14 100644 --- a/src/ipv4.rs +++ b/src/ipv4.rs @@ -215,9 +215,8 @@ impl Ipv4Network { /// assert_eq!(tinynet.size(), 1); /// ``` pub fn size(self) -> u32 { - let host_bits = u32::from(IPV4_BITS - self.prefix); - (2 as u32).pow(host_bits) - } + 1 << (u32::from(IPV4_BITS - self.prefix)) + } /// 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. diff --git a/src/ipv6.rs b/src/ipv6.rs index 756c3a9..865d0ac 100644 --- a/src/ipv6.rs +++ b/src/ipv6.rs @@ -242,7 +242,7 @@ impl Ipv6Network { /// ``` pub fn size(&self) -> u128 { let host_bits = u32::from(IPV6_BITS - self.prefix); - (2 as u128).pow(host_bits) + 2u128.pow(host_bits) } }