| Crates.io | toga |
| lib.rs | toga |
| version | 1.0.8 |
| created_at | 2025-05-13 11:38:04.428693+00 |
| updated_at | 2025-09-19 16:47:09.859284+00 |
| description | Toga is a proc macro crate for cleaner and more ergonomic rust. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1671777 |
| size | 24,331 |
Toga is a proc macro crate for cleaner and more ergonomic rust.
const async unsafe inherent methods.where constraints, across all generated impls.self::-qualified trait paths.impl declarations and unify method and trait definitions.Add the crate to your Cargo.toml:
[dependencies.toga]
version = "*"
Then import the macro in your crate:
use toga::impls;
// Define some traits
trait Health<T> {
fn health(&self) -> T;
}
trait Wizard {
fn you_shall_not_pass(&self);
}
// A generic struct with a const parameter
struct Player<const A: usize, B>(B);
// Use the `impls!` macro to generate implementations
impls! {
impl<const A: usize, B> Player<A, B>
where
B: Clone;
// Inherent methods
pub fn hello_world(&self) {
println!("Hello, world!");
}
pub fn give_me_a_number(&self) -> u8 {
50
}
// Trait implementations
Wizard {
fn you_shall_not_pass(&self) {
println!("You shall not pass!");
}
}
Health<u8> {
fn health(&self) -> u8 {
100
}
}
}
fn main() {
let player: Player<5, _> = Player("Data");
player.hello_world();
assert_eq!(player.give_me_a_number(), 50);
player.you_shall_not_pass();
assert_eq!(player.health(), 100);
}
impls! {
impl<ImplGenerics> Type<TypeGenerics>
where
...;
// Inherent methods
#[attr]
fn method1(...) { ... }
// Trait blocks
path::ToTrait<TraitGenerics> {
fn trait_method(...) -> ... { ... }
}
}
impl, optional generics, and where clause.fn declarations before trait blocks.Apache-2.0