lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

mod.rs (635B)


      1 #![allow(dead_code)]
      2 
      3 use core::str::FromStr;
      4 
      5 use radroots_core::{Currency, Decimal, Money, Percent, Quantity, Unit};
      6 
      7 pub fn dec(s: &str) -> Decimal {
      8     Decimal::from_str(s).expect("valid decimal")
      9 }
     10 
     11 pub fn currency(code: &str) -> Currency {
     12     Currency::from_str(code).expect("valid currency")
     13 }
     14 
     15 pub fn money(amount: &str, code: &str) -> Money {
     16     Money::try_new(dec(amount), currency(code)).expect("valid money")
     17 }
     18 
     19 pub fn qty(amount: &str, unit: Unit) -> Quantity {
     20     Quantity::try_new(dec(amount), unit).expect("valid quantity")
     21 }
     22 
     23 pub fn percent(s: &str) -> Percent {
     24     Percent::from_str(s).expect("valid percent")
     25 }