summaryrefslogtreecommitdiff
path: root/src/library/mod.rs
diff options
context:
space:
mode:
authorMartin <mhaug@live.de>2021-12-26 17:34:04 +0100
committerMartin Haug <mhaug@live.de>2021-12-27 12:33:53 +0100
commit7efdcdf2472257102c6b4b30bf285e2058924070 (patch)
tree9749c485b4ef25d1d68fcd248917f891b9ec9677 /src/library/mod.rs
parentb22ce6f8b84e0a75d162feb6f3699e26f86f2453 (diff)
Apply simple suggestions from code review
Co-Authored-By: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'src/library/mod.rs')
-rw-r--r--src/library/mod.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/library/mod.rs b/src/library/mod.rs
index 313d423b..1c97f529 100644
--- a/src/library/mod.rs
+++ b/src/library/mod.rs
@@ -26,6 +26,7 @@ mod utility;
/// Helpful imports for creating library functionality.
mod prelude {
pub use std::fmt::{self, Debug, Formatter};
+ pub use std::num::NonZeroUsize;
pub use std::rc::Rc;
pub use typst_macros::properties;
@@ -172,6 +173,15 @@ castable! {
}
castable! {
+ prelude::NonZeroUsize,
+ Expected: "positive integer",
+ Value::Int(int) => int
+ .try_into()
+ .and_then(|n: usize| n.try_into())
+ .map_err(|_| "must be positive")?,
+}
+
+castable! {
String,
Expected: "string",
Value::Str(string) => string.into(),