achanda / ipnetwork

A library to work with CIDRs in rust
Apache License 2.0
121 stars 38 forks source link

const fn constructors #111

Closed faern closed 4 years ago

faern commented 4 years ago

We can now/soon have const fn constructors thanks to if statements now working in const on nightly: https://blog.rust-lang.org/inside-rust/2019/11/25/const-if-match.html

We could implement it now already with a nightly feature and duplicate all constructors and conditionally compile them with #[cfg(feature = "nightly")]. But unless there is significant demand we could just wait and hope it reaches stable in a few versions.

This would improve the usability of this crate a lot. One of the most common ways I define IP networks in my code is global constants, which I currently have to use lazy_static! or similar to achieve.

faern commented 4 years ago

Adding the link to the tracking issue for if in const fns here. For reference. https://github.com/rust-lang/rust/issues/49146