Crate roman_literals
source · [−]Expand description
roman-literals
roman-literals
provides an easy way to write integer literals using Roman
numerals.
Features
- Supports all integers from I to MMMCMXCIX (1 to 3999)
- Type inference with the
roman!
macro - Zero cost!
Usage
-
Type aliases like
iXXXII
are provided to replace primitive types likei32
. -
Using the
roman!
macro, the type of the literal is automatically inferred, withiXXXII
being the default. The macro also supports negative numbers; seeroman!
for more details. -
Constants are also provided, such as
III_uXXXII
. These constants are all suffixed with their type. See theconsts
module for more details.
Examples
use roman_literals::*; // roman! macro and type aliases
let forty_two: uXXXII = roman!(XLII);
assert_eq!(forty_two, 42);
let negative_3999: iXVI = roman!(-MMMCMXCIX);
assert_eq!(negative_3999, -3999);
use roman_literals::consts::*; // to get the constants
let negative_300 = -CCC_iLXIV; // i64
assert_eq!(negative_300, -300);
Why?
Why not?
Modules
Roman literals with explicit types.
Macros
Write a constant Roman numeral.
Type Definitions
The CXXVIII-bit signed integer type.
The LXIV-bit signed integer type.
The VIII-bit signed integer type.
The XVI-bit signed integer type.
The XXXII-bit signed integer type.
The CXXVIII-bit unsigned integer type.
The LXIV-bit unsigned integer type.
The VIII-bit unsigned integer type.
The XVI-bit unsigned integer type.
The XXXII-bit unsigned integer type.