Macro naan::deriving

source ·
macro_rules! deriving {
    (impl$(<$($vars:ident),+>)? Functor<$hkt:ty, $a:ident> for $t:ty {..FunctorOnce}) => { ... };
    (impl$(<$($vars:ident),+>)? Bifunctor<$hkt:ty, $a:ident, $b:ident> for $t:ty {..BifunctorOnce}) => { ... };
    (impl$(<$($vars:ident),+>)? Apply<$hkt:ty, $ab:ident> for $t:ty {..ApplyOnce}) => { ... };
    (impl$(<$($vars:ident),+>)? Plus<$hkt:ty, $a:ident> for $t:ty {..Default}) => { ... };
    (impl$(<$($vars:ident),+>)? Semigroup for $t:ty {..Alt}) => { ... };
    (impl$(<$($vars:ident),+>)? Monoid for $t:ty {..Default}) => { ... };
    (impl$(<$($vars:ident),+>)? FoldableIndexed<$hkt:ty, $idx:ident, $a:ident> for $t:ty {..FoldableOnceIndexed}) => { ... };
    (impl$(<$($vars:ident),+>)? FoldableOnce<$hkt:ty, $a:ident> for $t:ty {..FoldableOnceIndexed}) => { ... };
    (impl$(<$($vars:ident),+>)? Foldable<$hkt:ty, $a:ident> for $t:ty {..FoldableOnce}) => { ... };
    (impl$(<$($vars:ident),+>)? Foldable<$hkt:ty, $a:ident> for $t:ty {..FoldableIndexed}) => { ... };
    (impl$(<$($vars:ident),+>)? Traversable<$hkt:ty, $a:ident, $b:ident, $tf:ty> for $t:ty {..TraversableOnce}) => { ... };
    (impl$(<$($vars:ident),+>)? Monad<$hkt:ty, $a:ident> for $t:ty {..MonadOnce}) => { ... };
}
Expand description

Helper macro that allows deriving various typeclass instances from other traits or typeclasses.

e.g. Functor can use the implementation for FunctorOnce, Plus can use Default.

use naan::prelude::*;

#[derive(Default)]
pub struct Foo(String);

impl Semigroup for Foo {
  fn append(self, other: Self) -> Self {
    Foo(self.0.append(other.0))
  }
}

deriving!(impl Monoid for Foo {..Default});