This crate is for converting to and from the roman numbers with strong emphasis on correctness. It supports only classic roman numbers, which means that it allows maximum 3 instances of the same number one after the other. This means that the biggest number which can be expressed as a roman numeral is 3999. Considering the fact that the number 0 doesn't exist in roman numerics, this crate only supports numbers from 1 to 3999.
```rust use roman::*;
let roman = Roman::fromstring("XII").unwrap(); asserteq!(roman.as_int(), 12);
let roman = Roman::frominteger(48).unwrap(); asserteq!(roman.as_string(), String::from("XLVIII")); ```
MIV applies strict rules on parsing the roman strings. It tries to make sure that the string passed is actually a valid roman numeral, not just a collection of numbers written in a row. For example:
```rust let valid143 = Roman::fromstring("CXLIII"); asserteq!(valid143, Ok(Roman(143)));
let invalidten = Roman::fromstring("IXI"); asserteq!(invalidten, Err(Error::InvalidSequence(Roman::IX, Roman::I)));
let invalidtwenty = Roman::fromstring("XVV"); asserteq!(invalidtwenty, Err(Error::InvalidSequence(Roman::V, Roman::V)));
let onesinthebeginning = Roman::fromstring("IIIX"); asserteq!(onesinthebeginning, Err(Error::InvalidSequence(Roman::I, Roman::IX))); ```
It also has other safeguards, like no more than 3 instances of the same number in a row, no empty strings, no non-roman characters, no number 0.