[−][src]Struct postgres_money::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.
fn add(self, rhs: Money) -> Self::Output
[src]
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]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Display for Money
[src]
impl Div<f32> for Money
[src]
type Output = Self
The resulting type after applying the /
operator.
fn div(self, rhs: f32) -> Self::Output
[src]
impl Div<f64> for Money
[src]
type Output = Self
The resulting type after applying the /
operator.
fn div(self, rhs: f64) -> Self::Output
[src]
impl Div<i16> for Money
[src]
type Output = Self
The resulting type after applying the /
operator.
fn div(self, rhs: i16) -> Self::Output
[src]
impl Div<i32> for Money
[src]
type Output = Self
The resulting type after applying the /
operator.
fn div(self, rhs: i32) -> Self::Output
[src]
impl Div<i64> for Money
[src]
type Output = Self
The resulting type after applying the /
operator.
fn div(self, rhs: i64) -> Self::Output
[src]
impl Div<i8> for Money
[src]
type Output = Self
The resulting type after applying the /
operator.
fn div(self, rhs: i8) -> Self::Output
[src]
impl Div<u16> for Money
[src]
type Output = Self
The resulting type after applying the /
operator.
fn div(self, rhs: u16) -> Self::Output
[src]
impl Div<u32> for Money
[src]
type Output = Self
The resulting type after applying the /
operator.
fn div(self, rhs: u32) -> Self::Output
[src]
impl Div<u8> for Money
[src]
type Output = Self
The resulting type after applying the /
operator.
fn div(self, rhs: u8) -> Self::Output
[src]
impl Eq for Money
[src]
impl<'a> FromSql<'a> for Money
[src]
fn from_sql(_: &Type, buf: &[u8]) -> Result<Money, Box<dyn Error + Sync + Send>>
[src]
fn accepts(ty: &Type) -> bool
[src]
fn from_sql_null(
ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Sync + Send>>
[src]
ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Sync + Send>>
fn from_sql_nullable(
ty: &Type,
raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Sync + Send>>
[src]
ty: &Type,
raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Sync + Send>>
impl FromStr for Money
[src]
type Err = Error
The associated error which can be returned from parsing.
fn from_str(money_str: &str) -> Result<Self, Self::Err>
[src]
impl Hash for Money
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Mul<Money> for i64
[src]
type Output = Money
The resulting type after applying the *
operator.
fn mul(self, rhs: Money) -> Self::Output
[src]
impl Mul<Money> for i32
[src]
type Output = Money
The resulting type after applying the *
operator.
fn mul(self, rhs: Money) -> Self::Output
[src]
impl Mul<Money> for i16
[src]
type Output = Money
The resulting type after applying the *
operator.
fn mul(self, rhs: Money) -> Self::Output
[src]
impl Mul<Money> for i8
[src]
type Output = Money
The resulting type after applying the *
operator.
fn mul(self, rhs: Money) -> Self::Output
[src]
impl Mul<Money> for u32
[src]
type Output = Money
The resulting type after applying the *
operator.
fn mul(self, rhs: Money) -> Self::Output
[src]
impl Mul<Money> for u16
[src]
type Output = Money
The resulting type after applying the *
operator.
fn mul(self, rhs: Money) -> Self::Output
[src]
impl Mul<Money> for u8
[src]
type Output = Money
The resulting type after applying the *
operator.
fn mul(self, rhs: Money) -> Self::Output
[src]
impl Mul<Money> for f64
[src]
type Output = Money
The resulting type after applying the *
operator.
fn mul(self, rhs: Money) -> Self::Output
[src]
impl Mul<Money> for f32
[src]
type Output = Money
The resulting type after applying the *
operator.
fn mul(self, rhs: Money) -> Self::Output
[src]
impl Mul<f32> for Money
[src]
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: f32) -> Self::Output
[src]
impl Mul<f64> for Money
[src]
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: f64) -> Self::Output
[src]
impl Mul<i16> for Money
[src]
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: i16) -> Self::Output
[src]
impl Mul<i32> for Money
[src]
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: i32) -> Self::Output
[src]
impl Mul<i64> for Money
[src]
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: i64) -> Self::Output
[src]
impl Mul<i8> for Money
[src]
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: i8) -> Self::Output
[src]
impl Mul<u16> for Money
[src]
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: u16) -> Self::Output
[src]
impl Mul<u32> for Money
[src]
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: u32) -> Self::Output
[src]
impl Mul<u8> for Money
[src]
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: u8) -> Self::Output
[src]
impl Ord for Money
[src]
fn cmp(&self, other: &Money) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<Money> for Money
[src]
impl PartialOrd<Money> for Money
[src]
fn partial_cmp(&self, other: &Money) -> Option<Ordering>
[src]
fn lt(&self, other: &Money) -> bool
[src]
fn le(&self, other: &Money) -> bool
[src]
fn gt(&self, other: &Money) -> bool
[src]
fn ge(&self, other: &Money) -> bool
[src]
impl Serialize for Money
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
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.
fn sub(self, rhs: Money) -> Self::Output
[src]
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T> FromSqlOwned for T where
T: for<'a> FromSql<'a>,
[src]
T: for<'a> FromSql<'a>,
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,