summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2024-02-25 12:50:11 +0100
committerGitHub <noreply@github.com>2024-02-25 11:50:11 +0000
commitca5d682edb1553cd73c581a1726537e6415fe848 (patch)
treef6914bb9727bd533543136d482baba21b0b3fc0f /crates
parent010da18d997eda16b894ec8be41f3e3d84e0ccd7 (diff)
Fix cast order for `ToInt` (#3485)
Diffstat (limited to 'crates')
-rw-r--r--crates/typst/src/foundations/array.rs2
-rw-r--r--crates/typst/src/foundations/float.rs2
-rw-r--r--crates/typst/src/foundations/int.rs2
-rw-r--r--crates/typst/src/visualize/color.rs2
4 files changed, 4 insertions, 4 deletions
diff --git a/crates/typst/src/foundations/array.rs b/crates/typst/src/foundations/array.rs
index 27f56194..b001aa20 100644
--- a/crates/typst/src/foundations/array.rs
+++ b/crates/typst/src/foundations/array.rs
@@ -803,8 +803,8 @@ pub struct ToArray(Array);
cast! {
ToArray,
- v: Bytes => Self(v.iter().map(|&b| Value::Int(b.into())).collect()),
v: Array => Self(v),
+ v: Bytes => Self(v.iter().map(|&b| Value::Int(b.into())).collect()),
v: Version => Self(v.values().iter().map(|&v| Value::Int(v as i64)).collect())
}
diff --git a/crates/typst/src/foundations/float.rs b/crates/typst/src/foundations/float.rs
index 723e023b..ee442a29 100644
--- a/crates/typst/src/foundations/float.rs
+++ b/crates/typst/src/foundations/float.rs
@@ -107,6 +107,7 @@ pub struct ToFloat(f64);
cast! {
ToFloat,
+ v: f64 => Self(v),
v: bool => Self(v as i64 as f64),
v: i64 => Self(v as f64),
v: Ratio => Self(v.get()),
@@ -114,7 +115,6 @@ cast! {
parse_float(v.clone().into())
.map_err(|_| eco_format!("invalid float: {}", v))?
),
- v: f64 => Self(v),
}
fn parse_float(s: EcoString) -> Result<f64, ParseFloatError> {
diff --git a/crates/typst/src/foundations/int.rs b/crates/typst/src/foundations/int.rs
index f7f8c0e8..ef21f785 100644
--- a/crates/typst/src/foundations/int.rs
+++ b/crates/typst/src/foundations/int.rs
@@ -229,10 +229,10 @@ pub struct ToInt(i64);
cast! {
ToInt,
+ v: i64 => Self(v),
v: bool => Self(v as i64),
v: f64 => Self(v as i64),
v: Str => Self(parse_int(&v).map_err(|_| eco_format!("invalid integer: {}", v))?),
- v: i64 => Self(v),
}
fn parse_int(mut s: &str) -> Result<i64, ParseIntError> {
diff --git a/crates/typst/src/visualize/color.rs b/crates/typst/src/visualize/color.rs
index 33d824e1..e22f668c 100644
--- a/crates/typst/src/visualize/color.rs
+++ b/crates/typst/src/visualize/color.rs
@@ -1916,8 +1916,8 @@ pub struct ChromaComponent(f32);
cast! {
ChromaComponent,
- v: Ratio => Self((v.get() * 0.4) as f32),
v: f64 => Self(v as f32),
+ v: Ratio => Self((v.get() * 0.4) as f32),
}
/// An integer or ratio component.