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

§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; }