[][src]Struct postgres_money::Money

pub struct Money(_);

Representation of the Postgres 'money' type

Implementations

impl Money[src]

pub fn parse_str(input: &str) -> Result<Money, Error>[src]

Attempt to parse a &str into a Money.

NOTE: as of this writing, only the Postgres en_US.UTF-8 locale is supported.

For more information about the Postgres money type, please see 8.2. Monetary Types.

For more about how locales work with monetary values, please see lc_monetary.

Examples

Parse a string of dollars

use postgres_money::Money;
let dollars = "324023040222";
let money = Money::parse_str(dollars).unwrap();

assert_eq!("$324023040222.00", money.to_string());

Parse a string of cents

use postgres_money::Money;
let dollars = ".32";
let money = Money::parse_str(dollars).unwrap();

assert_eq!("$0.32", money.to_string());

Parse a string with dollars and cents

use postgres_money::Money;
let dollars = "93.32";
let money = Money::parse_str(dollars).unwrap();

assert_eq!("$93.32", money.to_string());

Handles parentheses

use postgres_money::Money;
let dollars = "(93.32)";
let money = Money::parse_str(dollars).unwrap();

assert_eq!("-$93.32", money.to_string());

Handles dollar symbols

use postgres_money::Money;
let dollars = "$93.32";
let money = Money::parse_str(dollars).unwrap();

assert_eq!("$93.32", money.to_string());

Rounds correctly

use postgres_money::Money;
let dollars = "$123.454";
let money = Money::parse_str(dollars).unwrap();

assert_eq!("$123.45", money.to_string());

let dollars = "$123.455";
let money = Money::parse_str(dollars).unwrap();

assert_eq!("$123.46", money.to_string());

Handles commas

use postgres_money::Money;
let dollars = "$123,456.78";
let money = Money::parse_str(dollars).unwrap();

assert_eq!("$123456.78", money.to_string());

Max value

use postgres_money::Money;
let dollars = "92233720368547758.07";
let money = Money::parse_str(dollars).unwrap();

assert_eq!("$92233720368547758.07", money.to_string());
assert_eq!(Money::max().to_string(), money.to_string());

Min value

use postgres_money::Money;
let dollars = "-92233720368547758.08";
let money = Money::parse_str(dollars).unwrap();

assert_eq!("-$92233720368547758.08", money.to_string());
assert_eq!(Money::min().to_string(), money.to_string());

pub fn from(cents: i64) -> Money[src]

Construct a Money instance from an i64

Examples

use postgres_money::Money;
let cents = 324023040222;
let money = Money::from(cents);

assert_eq!("$3240230402.22", money.to_string());

impl Money[src]

pub const fn min() -> Money[src]

Minimum allowable value for Money

pub const fn max() -> Money[src]

Maximum allowable value for Money

pub const fn none() -> Money[src]

Instantiate Money as zero

pub const fn inner(&self) -> i64[src]

Expose the wrapped i64 value

Trait Implementations

impl Add<Money> for Money[src]

type Output = Self

The resulting type after applying the + operator.

impl Clone for Money[src]

impl Copy for Money[src]

impl Debug for Money[src]

impl Default for Money[src]

impl<'de> Deserialize<'de> for Money[src]

impl Display for Money[src]

impl Div<f32> for Money[src]

type Output = Self

The resulting type after applying the / operator.

impl Div<f64> for Money[src]

type Output = Self

The resulting type after applying the / operator.

impl Div<i16> for Money[src]

type Output = Self

The resulting type after applying the / operator.

impl Div<i32> for Money[src]

type Output = Self

The resulting type after applying the / operator.

impl Div<i64> for Money[src]

type Output = Self

The resulting type after applying the / operator.

impl Div<i8> for Money[src]

type Output = Self

The resulting type after applying the / operator.

impl Div<u16> for Money[src]

type Output = Self

The resulting type after applying the / operator.

impl Div<u32> for Money[src]

type Output = Self

The resulting type after applying the / operator.

impl Div<u8> for Money[src]

type Output = Self

The resulting type after applying the / operator.

impl Eq for Money[src]

impl<'a> FromSql<'a> for Money[src]

impl FromStr for Money[src]

type Err = Error

The associated error which can be returned from parsing.

impl Hash for Money[src]

impl Mul<Money> for i64[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<Money> for i32[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<Money> for i16[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<Money> for i8[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<Money> for u32[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<Money> for u16[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<Money> for u8[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<Money> for f64[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<Money> for f32[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<f32> for Money[src]

type Output = Self

The resulting type after applying the * operator.

impl Mul<f64> for Money[src]

type Output = Self

The resulting type after applying the * operator.

impl Mul<i16> for Money[src]

type Output = Self

The resulting type after applying the * operator.

impl Mul<i32> for Money[src]

type Output = Self

The resulting type after applying the * operator.

impl Mul<i64> for Money[src]

type Output = Self

The resulting type after applying the * operator.

impl Mul<i8> for Money[src]

type Output = Self

The resulting type after applying the * operator.

impl Mul<u16> for Money[src]

type Output = Self

The resulting type after applying the * operator.

impl Mul<u32> for Money[src]

type Output = Self

The resulting type after applying the * operator.

impl Mul<u8> for Money[src]

type Output = Self

The resulting type after applying the * operator.

impl Ord for Money[src]

impl PartialEq<Money> for Money[src]

impl PartialOrd<Money> for Money[src]

impl Serialize for Money[src]

impl StructuralEq for Money[src]

impl StructuralPartialEq for Money[src]

impl Sub<Money> for Money[src]

type Output = Self

The resulting type after applying the - operator.

impl ToSql for Money[src]

Auto Trait Implementations

impl RefUnwindSafe for Money

impl Send for Money

impl Sync for Money

impl Unpin for Money

impl UnwindSafe for Money

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> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

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

impl<T> FromSqlOwned for T where
    T: for<'a> FromSql<'a>, 
[src]

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

impl<T> Same<T> for T

type Output = T

Should always be Self

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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,