binexp

Crates.iobinexp
lib.rsbinexp
version0.1.1
sourcesrc
created_at2023-07-18 11:52:26.639649
updated_at2023-07-24 17:43:19.369821
descriptionA struct that represents power of two numbers.
homepage
repositoryhttps://github.com/Mirch/binexp
max_upload_size
id919401
size13,016
Mircea Teodor Oprea (Mirch)

documentation

README

binexp

CI crates

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.

Examples

use std::convert::TryFrom;
use binexp::PowerOfTwo;

assert!(PowerOfTwo::try_from(1).is_ok());
assert!(PowerOfTwo::try_from(2).is_ok());
assert!(PowerOfTwo::try_from(3).is_err());

let four = PowerOfTwo::try_from(4).unwrap();
assert_eq!(four.to_string(), "2^2 (4)");

let eight: PowerOfTwo = 8i8.try_into().unwrap();
assert_eq!(eight.to_string(), "2^3 (8)");

License

This project is licensed under the MIT license.

Commit count: 15

cargo fmt