Skip to content

Commit

Permalink
Merge pull request #950 from wetheredge/const-assert
Browse files Browse the repository at this point in the history
Use `assert!()` to check `prefix_len` in `Ipv4Cidr::new`
  • Loading branch information
thvdveld authored Jul 9, 2024
2 parents 99ddd22 + bbc3001 commit c937695
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/wire/ipv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,8 @@ impl Cidr {
///
/// # Panics
/// This function panics if the prefix length is larger than 32.
#[allow(clippy::no_effect)]
pub const fn new(address: Address, prefix_len: u8) -> Cidr {
// Replace with const panic (or assert) when stabilized
// see: https://github.com/rust-lang/rust/issues/51999
["Prefix length should be <= 32"][(prefix_len > 32) as usize];
assert!(prefix_len <= 32);
Cidr {
address,
prefix_len,
Expand Down

0 comments on commit c937695

Please sign in to comment.