summaryrefslogtreecommitdiff
path: root/src/eval/cast.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-10 12:55:21 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-10 12:55:21 +0100
commit62f35602a87574dcc607f1637aeae1be574981ff (patch)
tree363a1918006e06d7d79dc2ace5f8e59cd3b6bb19 /src/eval/cast.rs
parentc38d72383d2068361d635d6c1c78ba97aa917801 (diff)
New #[func] macro
Diffstat (limited to 'src/eval/cast.rs')
-rw-r--r--src/eval/cast.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/eval/cast.rs b/src/eval/cast.rs
index 840ceb05..806f7e92 100644
--- a/src/eval/cast.rs
+++ b/src/eval/cast.rs
@@ -1,6 +1,6 @@
pub use typst_macros::{cast_from_value, cast_to_value};
-use std::num::NonZeroUsize;
+use std::num::{NonZeroI64, NonZeroUsize};
use std::ops::Add;
use ecow::EcoString;
@@ -128,6 +128,20 @@ cast_to_value! {
}
cast_from_value! {
+ NonZeroI64,
+ int: i64 => int.try_into()
+ .map_err(|_| if int <= 0 {
+ "number must be positive"
+ } else {
+ "number too large"
+ })?,
+}
+
+cast_to_value! {
+ v: NonZeroI64 => Value::Int(v.get())
+}
+
+cast_from_value! {
char,
string: Str => {
let mut chars = string.chars();
@@ -211,6 +225,16 @@ impl<T: Into<Value>> From<Vec<T>> for Value {
}
}
+/// A container for a variadic argument.
+pub trait Variadics {
+ /// The contained type.
+ type Inner;
+}
+
+impl<T> Variadics for Vec<T> {
+ type Inner = T;
+}
+
/// Describes a possible value for a cast.
#[derive(Debug, Clone, Hash)]
pub enum CastInfo {