[][src]Struct xvii::Roman

pub struct Roman(_);

A Roman numeral.

This struct stores the value of a numeral as an NonZeroU16 but provides for Roman-style formatting.

Implementations

impl Roman[src]

pub fn new(n: u16) -> Result<Roman>[src]

Creates a Roman value based on a u16.

This function will return None if the value supplied is outside the acceptable range of 1..=4999, because numbers outside that range cannot be appropriately formatted using the seven standard numerals.

pub fn to_uppercase(self) -> String[src]

Formats a Roman value as an uppercase Roman numeral.

Examples

use xvii::Roman;
assert_eq!(Roman::new(42).unwrap().to_uppercase(), "XLII");

pub fn to_lowercase(self) -> String[src]

Formats a Roman value as a lowercase Roman numeral.

Examples

use xvii::Roman;
assert_eq!(Roman::new(42).unwrap().to_lowercase(), "xlii");

pub const fn format(&self, style: Style) -> RomanFormatter[src]

Returns a RomanFormatter which lazily formats a self value as a lowercase or uppercase Roman numeral depending of style.

Examples

use xvii::{Roman, Style};

let value = Roman::new(12).unwrap();
assert_eq!(format!("{}", value.format(Style::Upper)), "XII");
assert_eq!(value.format(Style::Lower).to_string(), "xii"); // `format!("{}")` and `.to_string()` are the same thing

pub const fn value(self) -> u16[src]

Returns value of this Roman numeral.

Examples

let roman = xvii::Roman::new(42).unwrap();
assert_eq!(roman.value(), 42);

pub const fn into_inner(self) -> NonZeroU16[src]

Returns the inner value.

Examples

let roman = xvii::Roman::new(42).unwrap();
assert_eq!(roman.into_inner(), std::num::NonZeroU16::new(42).unwrap());

Trait Implementations

impl Clone for Roman[src]

impl Copy for Roman[src]

impl Debug for Roman[src]

impl Display for Roman[src]

impl Eq for Roman[src]

impl FromStr for Roman[src]

type Err = Error

The associated error which can be returned from parsing.

impl Hash for Roman[src]

impl Ord for Roman[src]

impl PartialEq<Roman> for Roman[src]

impl PartialOrd<Roman> for Roman[src]

impl StructuralEq for Roman[src]

impl StructuralPartialEq for Roman[src]

Auto Trait Implementations

impl RefUnwindSafe for Roman

impl Send for Roman

impl Sync for Roman

impl Unpin for Roman

impl UnwindSafe for Roman

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.