Created
October 25, 2020 21:47
-
-
Save Robbepop/92397c085850b7a8decc55e080fbeffc to your computer and use it in GitHub Desktop.
Constant evulator for next_power_of_two in proc. macros.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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