mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-29 07:59:00 +00:00
templater: implement TemplateProperty for tuples up to 4-ary
A method call with arguments will be combined to (self, args...) tuple. Unary tuple is useless, but is implemented for consistency. This tuple_impls! macro is based off the serde one as the Rust core one requires unstable feature.
This commit is contained in:
parent
a4be118981
commit
54de6168f2
1 changed files with 22 additions and 0 deletions
|
@ -200,6 +200,28 @@ impl<C, P: TemplateProperty<C> + ?Sized> TemplateProperty<C> for Box<P> {
|
|||
}
|
||||
}
|
||||
|
||||
// Implement TemplateProperty for tuples
|
||||
macro_rules! tuple_impls {
|
||||
($( ( $($n:tt $T:ident),+ ) )+) => {
|
||||
$(
|
||||
impl<C, $($T: TemplateProperty<C>,)+> TemplateProperty<C> for ($($T,)+) {
|
||||
type Output = ($($T::Output,)+);
|
||||
|
||||
fn extract(&self, context: &C) -> Self::Output {
|
||||
($(self.$n.extract(context),)+)
|
||||
}
|
||||
}
|
||||
)+
|
||||
}
|
||||
}
|
||||
|
||||
tuple_impls! {
|
||||
(0 T0)
|
||||
(0 T0, 1 T1)
|
||||
(0 T0, 1 T1, 2 T2)
|
||||
(0 T0, 1 T1, 2 T2, 3 T3)
|
||||
}
|
||||
|
||||
/// Adapter to drop template context.
|
||||
pub struct Literal<O>(pub O);
|
||||
|
||||
|
|
Loading…
Reference in a new issue