Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to invoke some functions as const fn #43

Merged
merged 1 commit into from Dec 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/ipnet.rs
Expand Up @@ -558,7 +558,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);
}
Expand All @@ -583,17 +583,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
}

Expand Down Expand Up @@ -889,7 +889,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);
}
Expand All @@ -914,17 +914,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
}

Expand Down