From 8fcff82c7b29bd469baef090d6ea99199e91e5fb Mon Sep 17 00:00:00 2001 From: Abhishek Chanda Date: Thu, 27 Aug 2020 18:01:07 +0100 Subject: [PATCH] Convert Ipv{4,6}Network::new to const functions IpNetwork::new cannot be const since it is not supported with the ? operator Closes #111 --- src/ipv4.rs | 2 +- src/ipv6.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ipv4.rs b/src/ipv4.rs index 9b0395a..a944598 100644 --- a/src/ipv4.rs +++ b/src/ipv4.rs @@ -35,7 +35,7 @@ impl Ipv4Network { /// Constructs a new `Ipv4Network` from any `Ipv4Addr` and a prefix denoting the network size. /// /// If the prefix is larger than 32 this will return an `IpNetworkError::InvalidPrefix`. - pub fn new(addr: Ipv4Addr, prefix: u8) -> Result { + pub const fn new(addr: Ipv4Addr, prefix: u8) -> Result { if prefix > IPV4_BITS { Err(IpNetworkError::InvalidPrefix) } else { diff --git a/src/ipv6.rs b/src/ipv6.rs index 4013086..558bc6e 100644 --- a/src/ipv6.rs +++ b/src/ipv6.rs @@ -36,7 +36,7 @@ impl Ipv6Network { /// Constructs a new `Ipv6Network` from any `Ipv6Addr` and a prefix denoting the network size. /// /// If the prefix is larger than 128 this will return an `IpNetworkError::InvalidPrefix`. - pub fn new(addr: Ipv6Addr, prefix: u8) -> Result { + pub const fn new(addr: Ipv6Addr, prefix: u8) -> Result { if prefix > IPV6_BITS { Err(IpNetworkError::InvalidPrefix) } else {