Skip to main content

batch_impl

Attribute Macro batch_impl 

Source
#[batch_impl]
Expand description

Attribute macro that generates impl blocks for a trait in batch.

Annotate a trait definition with #[batch_impl(...)]; every impl-spec in the macro arguments generates a corresponding impl block for that trait.

§Syntax

#[batch_impl( impl-spec [, impl-spec]* [{ body }]? )]

An impl-spec has three parts (the tail of each part may be omitted):

  • <impl generics> — generic params of the impl block
  • Trait name<trait generics> — the trait’s generic args and associated type bindings
  • target type — wrapped in [] for a parallel list, ^/- for generic application

§ItemImpl entry (0.8.0, Ext 1)

The same attribute also accepts an impl block: the DSL describes a shape template × matrix source, and every matrix leaf instantiates the impl (the slot mapping rewrites the for-Type / where / body; the original impl is withheld):

#[batch_impl(Wrapper<T> : [Box, Rc]^u8)]
impl Mk for Wrapper<T> { fn make() -> Wrapper<T> { Wrapper::new(T::default()) } }
// → impl Mk for Box<u8> { fn make() -> Box<u8> { Box::new(u8::default()) } }
// → impl Mk for Rc<u8>  { fn make() -> Rc<u8>  { Rc::new(u8::default()) } }

§Examples

#[batch_impl(usize, isize)]
trait Numeric {}

#[batch_impl(<T> Vec<T>)]
trait Collection {}

#[batch_impl(<T> FromValue<T> [i32 { fn wrap(_: T) -> Self { 0 }}, u32 #wrap{0}] )]
trait FromValue<T> { fn wrap(val: T) -> Self; }

// #name{body} also supports const and type items
#[batch_impl(usize #MY_CONST{42})]
trait HasConst { const MY_CONST: usize; }