pub struct Num2Words { /* private fields */ }Expand description
Builder for num2words
Implementations
sourceimpl Num2Words
impl Num2Words
sourcepub fn new<T>(num: T) -> Self where
T: Into<Number>,
pub fn new<T>(num: T) -> Self where
T: Into<Number>,
Creates a new builder
Example:
use num2words::Num2Words;
assert_eq!(
Num2Words::new(42).to_words(),
Ok(String::from("forty-two"))
);sourcepub fn lang(self, lang: Lang) -> Self
pub fn lang(self, lang: Lang) -> Self
Sets the language of the output
For all of the available languages, see Lang.
Example:
use num2words::{Num2Words, Lang};
assert_eq!(
Num2Words::new(42).lang(Lang::English).to_words(),
Ok(String::from("forty-two"))
);sourcepub fn cardinal(self) -> Self
pub fn cardinal(self) -> Self
Sets the type of output to cardinal (forty-two)
Example:
use num2words::Num2Words;
assert_eq!(
Num2Words::new(42).cardinal().to_words(),
Ok(String::from("forty-two"))
);sourcepub fn ordinal(self) -> Self
pub fn ordinal(self) -> Self
Sets the type of output to ordinal (forty-second)
Example:
use num2words::Num2Words;
assert_eq!(
Num2Words::new(42).ordinal().to_words(),
Ok(String::from("forty-second"))
);sourcepub fn ordinal_num(self) -> Self
pub fn ordinal_num(self) -> Self
Sets the type of output to numbered ordinal (42nd)
Example:
use num2words::Num2Words;
assert_eq!(
Num2Words::new(42).ordinal_num().to_words(),
Ok(String::from("42nd"))
);sourcepub fn year(self) -> Self
pub fn year(self) -> Self
Sets the type of output to year (nineteen oh-one)
Example:
use num2words::Num2Words;
assert_eq!(
Num2Words::new(1901).year().to_words(),
Ok(String::from("nineteen oh-one"))
);sourcepub fn currency(self, currency: Currency) -> Self
pub fn currency(self, currency: Currency) -> Self
Sets the output to the currency it has been given
For all of the available currencies, see Currency.
Example:
use num2words::{Num2Words, Currency};
assert_eq!(
Num2Words::new(42.01).currency(Currency::DOLLAR).to_words(),
Ok(String::from("forty-two dollars and one cent"))
);Auto Trait Implementations
impl RefUnwindSafe for Num2Words
impl Send for Num2Words
impl Sync for Num2Words
impl Unpin for Num2Words
impl UnwindSafe for Num2Words
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more