toga
Toga is a proc macro crate for cleaner and more ergonomic rust.
Features
- Single-Block Syntax: Define inherent methods and multiple trait implementations for a type within one macro invocation.
- Generics & Where Clauses: Preserve type and trait generics, as well as
whereconstraints, across all generatedimpls. - Flexible Trait Paths: Support for absolute, relative, and
self::-qualified trait paths. - Reduced Boilerplate: Eliminate repetitive
impldeclarations and unify method and trait definitions.
Installation
Add the crate to your Cargo.toml:
[]
= "*"
Then import the macro in your crate:
use impls;
Usage
// Define some traits
// A generic struct with a const parameter
;
// Use the `impls!` macro to generate implementations
impls!
Macro Syntax
impls! {
impl<ImplGenerics> Type<TypeGenerics>
where
...;
// Inherent methods
fn method1(...) { ... }
// Trait blocks
path::ToTrait<TraitGenerics> {
fn trait_method(...) -> ... { ... }
}
}
- Header: Starts with
impl, optional generics, andwhereclause. - Inherent Methods: Any
fndeclarations before trait blocks. - Trait Blocks: Blocks prefixed by a trait path are parsed as trait implementations.
License
Apache-2.0