const_arithmetic/lib.rs
1//! This crate is dedicated to implementing integer arithmetic that can be verified and used during compilation time
2
3mod hex;
4mod integer;
5mod binary;
6
7pub use hex::{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _A, _B, _C, _D, _E, _F, Hex, HexAdd, HexAdd3, HexMul, HexEqual, HexAssertEqual};
8pub use binary::{Binary, BinAnd, BinEq, BinNor, BinNot, BinOr, AssertFalse, AssertTrue};
9pub use integer::{TypedAssertEqual, TypedEqual, TypedGeq, TypedGreaterThan, TypedLessThan, TypedLeq, TypedInteger, TypedAdd, TypedSub, TypedMul, TypedDiv, IsInteger};
10pub use std::marker::PhantomData;
11
12#[doc(hidden)]
13pub use const_arith_macros_178::{parse_integer_inner, typed_assert_eq_inner};
14
15/// Turns an integer (u32) into a typed integer object.
16///
17/// Example
18/// ```
19/// use const_arithmetic::*;
20/// let a = parse_integer!(3);
21/// // Now `a` is a Typed integer object
22///
23/// // The expression must be a literal integer smaller than 4294967296 = 2**32
24/// // let a = parse_integer!(-1); // This does not compile
25/// // let a = parse_integer!(999999999999999999999999999999999); // This does not compile
26/// // const hiya: u32 = 5;
27/// // let a = parse_integer!(hiya); // This does not compile
28/// ```
29#[macro_export]
30macro_rules! parse_integer {
31 ($s:expr) => {
32 parse_integer_inner!($s)
33 };
34}
35
36#[macro_export]
37/// This asserts the typed integer provided is the same as the number you provided
38///
39/// Example
40/// ```
41/// use const_arithmetic::*;
42/// let a = parse_integer!(3);
43/// typed_assert_eq!(a, 3);
44/// ```
45macro_rules! typed_assert_eq {
46 ($a:ident, $val:expr) => {{
47 typed_assert_eq_inner!($val);
48 asserting(&$a);
49 }};
50}