summaryrefslogtreecommitdiff
path: root/macros
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-12-30 12:12:19 +0100
committerLaurenz <laurmaedje@gmail.com>2021-12-30 12:12:19 +0100
commitf174134aa23e96a2121fb4106fb23fbdad4d641a (patch)
tree7c842c8af3383805bbc7b835daecc71e8ba616e6 /macros
parent5d5d8a21cfc041ab08d30229f4ecb4cbb415cbc5 (diff)
Style chains
Diffstat (limited to 'macros')
-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.