pub struct Roman { /* private fields */ }Expand description
The main struct for romantic.
Implementations§
Source§impl Roman
impl Roman
Sourcepub fn new(character_set: &[char]) -> Self
pub fn new(character_set: &[char]) -> Self
Creates a new Roman using the characters in character_set.
The order of the character_set determines their magnitude, for example
using the default numeral system:
| Index | Magnitude | Character |
|---|---|---|
| 0 | 1 | ‘I’ |
| 1 | 5 | ‘V’ |
| 2 | 10 | ‘X’ |
| 3 | 50 | ‘L’ |
| 4 | 100 | ‘C’ |
| 5 | 500 | ‘D’ |
| 6 | 1000 | ‘M’ |
| … | … | … |
§Example
use romantic::Roman;
let roman = Roman::default();
assert_eq!(roman.to_string(9).unwrap(), "IX");
assert_eq!(roman.from_str::<i32>("IX").unwrap(), 9);
let custom = Roman::new(&['A', 'B', 'C']);
assert_eq!(custom.to_string(9).unwrap(), "AC");
assert_eq!(custom.from_str::<i32>("AC").unwrap(), 9);Sourcepub fn from_str<T: PrimInt>(&self, input: &str) -> Result<T, ConversionError>
pub fn from_str<T: PrimInt>(&self, input: &str) -> Result<T, ConversionError>
Converts a str to a generic integer num::PrimInt.
§Example
use romantic::Roman;
let roman = Roman::default();
assert_eq!(roman.from_str::<i32>("IX").unwrap(), 9);
let custom = Roman::new(&['A', 'B', 'C']);
assert_eq!(custom.from_str::<i32>("AC").unwrap(), 9);Sourcepub fn to_string<T: PrimInt + ToString>(
&self,
number: T,
) -> Result<String, ConversionError>
pub fn to_string<T: PrimInt + ToString>( &self, number: T, ) -> Result<String, ConversionError>
Converts a generic integer num::PrimInt to a String.
§Example
use romantic::Roman;
let roman = Roman::default();
assert_eq!(roman.to_string(9).unwrap(), "IX");
let custom = Roman::new(&['A', 'B', 'C']);
assert_eq!(custom.to_string(9).unwrap(), "AC");Trait Implementations§
Auto Trait Implementations§
impl Freeze for Roman
impl RefUnwindSafe for Roman
impl Send for Roman
impl Sync for Roman
impl Unpin for Roman
impl UnwindSafe for Roman
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more