pub struct Decimal(pub BigDecimal);Expand description
An exact decimal number of any precision, for numeric/decimal
columns: field score: Option<Decimal>. It’s stored exactly on Postgres
(as REAL on SQLite) and written as Rails writes a BigDecimal: "50.0",
"0.25", as a string, so no precision is lost on the way to a client.
Arithmetic is exact, and division rounds as Ruby’s BigDecimal#/ does
(see Div), so averages match a Rails app’s to
the last digit.
Tuple Fields§
§0: BigDecimalImplementations§
Trait Implementations§
Source§impl<'r> Decode<'r, Postgres> for Decimal
impl<'r> Decode<'r, Postgres> for Decimal
Source§fn decode(value: PgValueRef<'r>) -> Result<Self, BoxDynError>
fn decode(value: PgValueRef<'r>) -> Result<Self, BoxDynError>
Source§impl<'r> Decode<'r, Sqlite> for Decimal
impl<'r> Decode<'r, Sqlite> for Decimal
Source§fn decode(value: SqliteValueRef<'r>) -> Result<Self, BoxDynError>
fn decode(value: SqliteValueRef<'r>) -> Result<Self, BoxDynError>
Source§impl Display for Decimal
As ActiveSupport’s BigDecimal#to_s: plain digits (never exponent
notation), no trailing zeros, but always a fractional part: 50.0,
50.25.
impl Display for Decimal
As ActiveSupport’s BigDecimal#to_s: plain digits (never exponent
notation), no trailing zeros, but always a fractional part: 50.0,
50.25.
Source§impl Div for Decimal
Division as Ruby’s BigDecimal#/ (bigdecimal 3.1) computes it, so a
Rails app’s averages come out digit for digit: the quotient is kept to
the larger operand’s precision doubled (at least 32 digits) plus two
base-10⁹ words, truncated at a word boundary, then its last digit is
rounded half-up from an estimate of the next word.
impl Div for Decimal
Division as Ruby’s BigDecimal#/ (bigdecimal 3.1) computes it, so a
Rails app’s averages come out digit for digit: the quotient is kept to
the larger operand’s precision doubled (at least 32 digits) plus two
base-10⁹ words, truncated at a word boundary, then its last digit is
rounded half-up from an estimate of the next word.
§Panics
On division by zero, as integer division does (Ruby raises
ZeroDivisionError).
Source§impl Encode<'_, Postgres> for Decimal
Written as Rails writes a BigDecimal (its to_s): no trailing
zeros but at least one decimal place, so 100 is stored as 100.0.
impl Encode<'_, Postgres> for Decimal
Written as Rails writes a BigDecimal (its to_s): no trailing
zeros but at least one decimal place, so 100 is stored as 100.0.
Source§fn encode_by_ref(
&self,
buf: &mut PgArgumentBuffer,
) -> Result<IsNull, BoxDynError>
fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, BoxDynError>
Source§fn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, Box<dyn Error + Send + Sync>>where
Self: Sized,
fn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, Box<dyn Error + Send + Sync>>where
Self: Sized,
self into buf in the expected format for the database.fn produces(&self) -> Option<<DB as Database>::TypeInfo>
fn size_hint(&self) -> usize
Source§impl Encode<'_, Sqlite> for Decimal
impl Encode<'_, Sqlite> for Decimal
Source§fn encode_by_ref(
&self,
buf: &mut SqliteArgumentsBuffer,
) -> Result<IsNull, BoxDynError>
fn encode_by_ref( &self, buf: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, BoxDynError>
Source§fn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, Box<dyn Error + Send + Sync>>where
Self: Sized,
fn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, Box<dyn Error + Send + Sync>>where
Self: Sized,
self into buf in the expected format for the database.fn produces(&self) -> Option<<DB as Database>::TypeInfo>
fn size_hint(&self) -> usize
impl Eq for Decimal
Source§impl From<BigDecimal> for Decimal
impl From<BigDecimal> for Decimal
Source§fn from(value: BigDecimal) -> Self
fn from(value: BigDecimal) -> Self
Source§impl Number for Decimal
impl Number for Decimal
Source§fn delimited(&self) -> String
fn delimited(&self) -> String
1234567.delimited() is
"1,234,567", 1234.5.delimited() is "1,234.5".Source§fn to_currency(&self, code: &str) -> String
fn to_currency(&self, code: &str) -> String
1234.5.to_currency("GBP") is "£1,234.50"; "JPY" has no
decimals; a currency without a known symbol is written before the
amount ("CHF 12.00").Source§impl Ord for Decimal
impl Ord for Decimal
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Decimal
impl PartialOrd for Decimal
impl StructuralPartialEq for Decimal
Auto Trait Implementations§
impl Freeze for Decimal
impl RefUnwindSafe for Decimal
impl Send for Decimal
impl Sync for Decimal
impl Unpin for Decimal
impl UnsafeUnpin for Decimal
impl UnwindSafe for Decimal
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> FromColumn for Twhere
T: Decode + Decode + Send + 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more