Another approach to the nonzero macro
Rust Internals
Another approach to the nonzero macro
Initialization of a nonzero number, where assertion happens at compile time: // Using macro_rules for performant compilation, tested to work in stable Rust #[macro_export] macro_rules! nonzero { ($n:expr) => { // This is in a const context const { // Constant assertion that works even when running `cargo check` const _: () = { if $n == 0 { ::core::panic!("Cannot be zero!") } }; // SAFETY: Checked that $n is not...
0 comments
No comments yet.