Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Constant evulator for next_power_of_two in proc. macros.
fn const_next_power_of_two(ty: TokenStream2, value: TokenStream2) -> TokenStream2 {
quote! {{
if (#value) <= 1 {
0
} else {
let p = (#value) - 1;
let z = p.leading_zeros();
<#ty>::MAX as usize >> z
}
}}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment