binexp provides a PowerOfTwo
struct that you can create from any valid power of two integer.
You can use PowerOfTwo
as a safe way to represent powers of two in your code.
``` use std::convert::TryFrom; use binexp::PowerOfTwo;
assert!(PowerOfTwo::tryfrom(1).isok()); assert!(PowerOfTwo::tryfrom(2).isok()); assert!(PowerOfTwo::tryfrom(3).iserr());
let four = PowerOfTwo::tryfrom(4).unwrap(); asserteq!(four.to_string(), "2^2 (4)");
let eight: PowerOfTwo = 8i8.tryinto().unwrap(); asserteq!(eight.to_string(), "2^3 (8)"); ```
This project is licensed under the MIT license.