diff --git a/bench/src/bench.rs b/bench/src/bench.rs index 052ef5d63..5acf15f80 100644 --- a/bench/src/bench.rs +++ b/bench/src/bench.rs @@ -21,7 +21,7 @@ fn benchmarks(c: &mut Criterion) { let mut env = Env::new(loader); - let scope = library::_new(); + let scope = library::new(); let state = State::default(); for case in CASES { diff --git a/src/eval/value.rs b/src/eval/value.rs index 84701b3da..33592e5d6 100644 --- a/src/eval/value.rs +++ b/src/eval/value.rs @@ -650,26 +650,30 @@ impl From for Value { } } -/// Make a type usable as a [`Value`]. +/// Mark a type as a [`Value`]. /// /// Given a type `T`, this implements the following traits: /// - [`Type`] for `T`, /// - [`Cast`](Cast) for `T`. /// /// # Example -/// Allow a type `FontFamily` to be cast from: -/// - a [`Value::Any`] variant already containing a `FontFamily` -/// - a string, producing a `FontFamiliy::Named(..)`. /// ``` -/// # use typst::typify; -/// # enum FontFamily { Named(String) } -/// typify! { +/// # use typst::value; +/// enum FontFamily { +/// Serif, +/// Named(String), +/// } +/// +/// value! { /// FontFamily: "font family", -/// Value::Str(string) => Self::Named(string.to_lowercase()) +/// Value::Str(string) => Self::Named(string), /// } /// ``` +/// This would allow the type `FontFamily` to be cast from: +/// - a [`Value::Any`] variant already containing a `FontFamily`, +/// - a string, producing a named font family. #[macro_export] -macro_rules! typify { +macro_rules! value { ($type:ty: $type_name:literal $(, $pattern:pat => $out:expr)* diff --git a/src/library/align.rs b/src/library/align.rs index ccb25b346..3b1ea24ea 100644 --- a/src/library/align.rs +++ b/src/library/align.rs @@ -123,6 +123,6 @@ impl Display for AlignValue { } } -typify! { +value! { AlignValue: "alignment", } diff --git a/src/library/font.rs b/src/library/font.rs index cf329567d..df7b90058 100644 --- a/src/library/font.rs +++ b/src/library/font.rs @@ -132,7 +132,7 @@ pub fn font(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { #[derive(Debug, Clone, PartialEq)] struct FontFamilies(Vec); -typify! { +value! { FontFamilies: "string or array of strings", Value::Str(string) => Self(vec![string.to_lowercase()]), Value::Array(values) => Self(values @@ -143,16 +143,16 @@ typify! { ), } -typify! { +value! { FontFamily: "font family", Value::Str(string) => Self::Named(string.to_lowercase()) } -typify! { +value! { FontStyle: "font style", } -typify! { +value! { FontWeight: "font weight", Value::Int(number) => { let [min, max] = [Self::THIN, Self::BLACK]; @@ -172,7 +172,7 @@ typify! { }, } -typify! { +value! { FontStretch: "font stretch", Value::Relative(relative) => { let [min, max] = [Self::ULTRA_CONDENSED, Self::ULTRA_EXPANDED]; @@ -193,6 +193,6 @@ typify! { }, } -typify! { +value! { VerticalFontMetric: "vertical font metric", } diff --git a/src/library/mod.rs b/src/library/mod.rs index 2cfe02ba5..6e7966a06 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -1,6 +1,6 @@ //! The standard library. //! -//! Call [`_new`] to obtain a [`Scope`] containing all standard library +//! Call [`new`] to obtain a [`Scope`] containing all standard library //! definitions. mod align; @@ -40,7 +40,7 @@ use crate::geom::*; use crate::syntax::{Node, Spanned}; /// Construct a scope containing all standard library definitions. -pub fn _new() -> Scope { +pub fn new() -> Scope { let mut std = Scope::new(); macro_rules! func { @@ -120,6 +120,6 @@ pub fn _new() -> Scope { std } -typify! { +value! { Dir: "direction" } diff --git a/src/main.rs b/src/main.rs index fa98d4c51..9a112d5a5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,7 +40,7 @@ fn main() -> anyhow::Result<()> { let mut env = Env::new(loader); - let scope = library::_new(); + let scope = library::new(); let state = State::default(); let Pass { output: frames, diags } = typeset(&mut env, &src, &scope, state); diff --git a/tests/typeset.rs b/tests/typeset.rs index f60b81f75..1e1964468 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -211,7 +211,7 @@ fn test_part( let (local_compare_ref, ref_diags) = parse_metadata(src, &map); let compare_ref = local_compare_ref.unwrap_or(compare_ref); - let mut scope = library::_new(); + let mut scope = library::new(); let panics = Rc::new(RefCell::new(vec![])); register_helpers(&mut scope, Rc::clone(&panics));