summaryrefslogtreecommitdiff
path: root/macros/src/lib.rs
diff options
context:
space:
mode:
authorMartin <mhaug@live.de>2022-01-01 12:56:03 +0100
committerGitHub <noreply@github.com>2022-01-01 12:56:03 +0100
commit28fc2893e873d44aa31a64a87cb3e2e975977a70 (patch)
treebad022650bb488492386e4fc079dde3807b89304 /macros/src/lib.rs
parent5d5d8a21cfc041ab08d30229f4ecb4cbb415cbc5 (diff)
parent179a9f479831c4941253c0517fccdec3acd8f2ff (diff)
Merge pull request #53 from typst/style-chains
Diffstat (limited to 'macros/src/lib.rs')
-rw-r--r--macros/src/lib.rs23
1 files changed, 16 insertions, 7 deletions
diff --git a/macros/src/lib.rs b/macros/src/lib.rs
index 3b1d0548..55e597b1 100644
--- a/macros/src/lib.rs
+++ b/macros/src/lib.rs
@@ -47,7 +47,7 @@ fn expand(mut impl_block: syn::ItemImpl) -> Result<TokenStream2> {
mod #module {
use std::marker::PhantomData;
use once_cell::sync::Lazy;
- use crate::eval::{Property, StyleId};
+ use crate::eval::{Nonfolding, Property, StyleId};
use super::*;
#impl_block
@@ -106,17 +106,24 @@ fn process_const(
// initialization value of the const.
let default = &item.expr;
+ let mut folder = None;
+ let mut nonfolding = Some(quote! {
+ impl<T: 'static> Nonfolding for Key<T> {}
+ });
+
// Look for a folding function like `#[fold(u64::add)]`.
- let mut combinator = None;
for attr in &item.attrs {
if attr.path.is_ident("fold") {
- let fold: syn::Expr = attr.parse_args()?;
- combinator = Some(quote! {
- fn combine(inner: Self::Value, outer: Self::Value) -> Self::Value {
- let f: fn(Self::Value, Self::Value) -> Self::Value = #fold;
+ let func: syn::Expr = attr.parse_args()?;
+ folder = Some(quote! {
+ const FOLDABLE: bool = true;
+
+ fn fold(inner: Self::Value, outer: Self::Value) -> Self::Value {
+ let f: fn(Self::Value, Self::Value) -> Self::Value = #func;
f(inner, outer)
}
});
+ nonfolding = None;
}
}
@@ -136,8 +143,10 @@ fn process_const(
&*LAZY
}
- #combinator
+ #folder
}
+
+ #nonfolding
};
// The module that will contain the `Key` type.