This repository was archived by the owner on Jun 25, 2025. It is now read-only.
Repository navigation
Released Version0.1.0
Bug Fix
- Fixed a bug where declaring an enum with more than 4 variants could no longer compile.
- Fixed a bug that caused a compilation error when a method with generics that could not be inferred was defined; for example, something like below.
#[delegate]
trait Trait {
// Cannot guess the type of S at the time of delegation
fn sample<S>(&self);
}Features
Support for Unnamed Fields
You can now write the following for a field in the Tuple Struct.
#[derive(Delegate, Default)]
struct Parent(#[to(Increment)]Child);Support for delegation of static methods
Traits with static methods should not be used on Enums, as currently using them with Enums will not cause compilation errors, but will likely disable them in the future.
If used for Enum, the static method corresponding to the first variant is called.
use auto_delegate::{delegate, Delegate};
#[delegate]
trait StaticTrait {
fn static_method() -> usize;
}
struct Child1;
impl StaticTrait for Child1 {
fn static_method() -> usize {
1
}
}
struct Child2;
impl StaticTrait for Child2 {
fn static_method() -> usize {
2
}
}
#[derive(Delegate)]
#[to(StaticTrait)]
enum Parent {
Child1(Child1),
Child2(Child2),
}
fn main() {
// `Child1::static_method` is called
assert_eq!(Parent::static_method(), 1);
}