Rust library for roman numerals. Encode/decode roman numerals with ease!
Add this to your Cargo.toml
:
toml
[dependencies]
roman_numeral = "0.1"
Example
```rust use roman_numeral::{RomanNumeral, RomanNumeralError};
// Create roman numeral let roman = RomanNumeral::fromstring("I").unwrap(); asserteq!(roman.get_u32(), 1);
let roman = RomanNumeral::fromu32(49).unwrap(); asserteq!(roman.get(), String::from("XLIX"));
// Get roman numeral (string) let roman = RomanNumeral::from_u32(3999).unwrap(); let numeral = roman.get(); // MMMCMXCIX
// Get roman numeral decimal value let roman = RomanNumeral::fromstring("CXXV").unwrap(); let decimalvalue = roman.get_u32(); // 125
// Get maximum possible value let maxvalue = RomanNumeral::maxvalue(); asserteq!(maxvalue, 3999);
// Invalid input let error = RomanNumeral::fromstring("IIII").unwraperr(); assert_eq!(error, RomanNumeralError::InvalidStr);
let error = RomanNumeral::fromu32(0).unwraperr(); assert_eq!(error, RomanNumeralError::NumberOutOfRange);
let error = RomanNumeral::fromu32(4000).unwraperr(); assert_eq!(error, RomanNumeralError::NumberOutOfRange); ```