From 89d96c623dc882fcdbff02e201bcfb27e6bbfd2a Mon Sep 17 00:00:00 2001 From: +merlan #flirora Date: Wed, 27 Nov 2024 11:36:04 -0500 Subject: Let decimal constructor accept decimal values (#5481) --- crates/typst-library/src/foundations/decimal.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'crates') diff --git a/crates/typst-library/src/foundations/decimal.rs b/crates/typst-library/src/foundations/decimal.rs index cf11e1dd..d363a6a4 100644 --- a/crates/typst-library/src/foundations/decimal.rs +++ b/crates/typst-library/src/foundations/decimal.rs @@ -317,6 +317,7 @@ impl Decimal { }) .at(value.span) } + ToDecimal::Decimal(decimal) => Ok(decimal), } } } @@ -429,6 +430,8 @@ impl Hash for Decimal { /// A value that can be cast to a decimal. pub enum ToDecimal { + /// A decimal to be converted to itself. + Decimal(Decimal), /// A string with the decimal's representation. Str(EcoString), /// An integer to be converted to the equivalent decimal. @@ -439,7 +442,9 @@ pub enum ToDecimal { cast! { ToDecimal, + v: Decimal => Self::Decimal(v), v: i64 => Self::Int(v), + v: bool => Self::Int(v as i64), v: f64 => Self::Float(v), v: Str => Self::Str(EcoString::from(v)), } -- cgit v1.2.3