It may also be worth adding that this is a good test for unsigned integers, but will not work in general for signed integers when using rust. Since len() always returns a positive number (usize) this is a safe test in the above code.
If you're trying to test odd/even for something that could be positive or negative, the n % 2 == 0 test is a better choice.
Hey I was wondering why you used PhantomData here, I don't fully understand what the motivation is. Do you mind explaining why you decided to use it?
It may also be worth adding that this is a good test for unsigned integers, but will not work in general for signed integers when using rust. Since
len()
always returns a positive number (usize
) this is a safe test in the above code.If you're trying to test odd/even for something that could be positive or negative, the
n % 2 == 0
test is a better choice.