Merge pull request #43 from tetsuharuohzeki/const_fn

Allow to invoke some functions as const fn
This commit is contained in:
krisprice
2022-12-11 10:29:02 -08:00
committed by GitHub
+8 -8
View File
@@ -578,7 +578,7 @@ impl Ipv4Net {
/// let bad_prefix_len = Ipv4Net::new(Ipv4Addr::new(10, 1, 1, 0), 33);
/// assert_eq!(bad_prefix_len, Err(PrefixLenError));
/// ```
pub fn new(ip: Ipv4Addr, prefix_len: u8) -> Result<Ipv4Net, PrefixLenError> {
pub const fn new(ip: Ipv4Addr, prefix_len: u8) -> Result<Ipv4Net, PrefixLenError> {
if prefix_len > 32 {
return Err(PrefixLenError);
}
@@ -622,17 +622,17 @@ impl Ipv4Net {
}
/// Returns the address.
pub fn addr(&self) -> Ipv4Addr {
pub const fn addr(&self) -> Ipv4Addr {
self.addr
}
/// Returns the prefix length.
pub fn prefix_len(&self) -> u8 {
pub const fn prefix_len(&self) -> u8 {
self.prefix_len
}
/// Returns the maximum valid prefix length.
pub fn max_prefix_len(&self) -> u8 {
pub const fn max_prefix_len(&self) -> u8 {
32
}
@@ -931,7 +931,7 @@ impl Ipv6Net {
/// let bad_prefix_len = Ipv6Net::new(Ipv6Addr::new(0xfd, 0, 0, 0, 0, 0, 0, 0), 129);
/// assert_eq!(bad_prefix_len, Err(PrefixLenError));
/// ```
pub fn new(ip: Ipv6Addr, prefix_len: u8) -> Result<Ipv6Net, PrefixLenError> {
pub const fn new(ip: Ipv6Addr, prefix_len: u8) -> Result<Ipv6Net, PrefixLenError> {
if prefix_len > 128 {
return Err(PrefixLenError);
}
@@ -975,17 +975,17 @@ impl Ipv6Net {
}
/// Returns the address.
pub fn addr(&self) -> Ipv6Addr {
pub const fn addr(&self) -> Ipv6Addr {
self.addr
}
/// Returns the prefix length.
pub fn prefix_len(&self) -> u8 {
pub const fn prefix_len(&self) -> u8 {
self.prefix_len
}
/// Returns the maximum valid prefix length.
pub fn max_prefix_len(&self) -> u8 {
pub const fn max_prefix_len(&self) -> u8 {
128
}