Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

Releases

Released Version0.1.3

Choose a tag to compare

@not-elm not-elm released this 01 Jul 15:33

Bug fix

  • We can now use traits with associated types.

V0.1.2 Fixed async trait fn

Choose a tag to compare

@not-elm not-elm released this 25 Feb 11:38

Bug Fix

  • Fixed a bug that caused the definition of traits with immutable references as receivers to fail.

Released Version0.1.0

Choose a tag to compare

@not-elm not-elm released this 15 Feb 15:57

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

V0.0.8 Supported self-receiver and fix bugs

Choose a tag to compare

@not-elm not-elm released this 28 Aug 12:26

Functions that take self as an argument are now available from this version like this:

#[delegate]
trait Calc {
    fn calc(self, x1: usize, x2: usize) -> usize;
}

In addition, a bug around lifetime has been fixed.

Fixed IntelliSense Working on Clion

Choose a tag to compare

@not-elm not-elm released this 09 Jul 05:44

V0.0.6 Supported Stable Channel

Choose a tag to compare

@not-elm not-elm released this 03 Jun 12:58

The previous version could only operate nightly, but from this version it will be able to operate in Stable.

V0.0.5 Super traits

Choose a tag to compare

@not-elm not-elm released this 29 May 16:43

Supported Supertrait.

use auto_delegate_macros::{delegate, Delegate};

#[delegate]
trait Calc {
    fn calc(&self, x1: usize, x2: usize) -> usize;
}


#[delegate]
trait Label {
    fn label(&self) -> String;
}


#[delegate]
trait Increment: Calc + Label {
    fn increment(&mut self) -> usize;
}


#[derive(Default)]
struct Child {
    num: usize,
}


impl Increment for Child {
    fn increment(&mut self) -> usize {
        self.num += 1;
        self.num
    }
}


impl Calc for Child {
    fn calc(&self, x1: usize, x2: usize) -> usize {
        x1 + x2
    }
}


impl Label for Child {
    fn label(&self) -> String {
        String::from("add")
    }
}

#[derive(Default, Delegate)]
struct Parent {
    #[to(Calc, Increment, Label)]
    child: Child,
}


fn main() {
    let mut parent = Parent::default();
    assert_eq!(parent.increment(), 1);
    assert_eq!(parent.increment(), 2);
    assert_eq!(parent.calc(3, 2), 5);
    assert_eq!(parent.label(), "add");
}

v0.0.4 async-trait

Choose a tag to compare

@not-elm not-elm released this 20 May 12:05

Support async traits

Correctly, it was fixed to properly handle lifetime bounds generated by async-trait.

By the way, v0.0.3 was published by mistake.

Example Heres:

#![feature(async_fn_in_trait)]
use async_trait::async_trait;
use auto_delegate::{Delegate, delegate};

#[async_trait]
#[delegate]
pub trait Calc {
    async fn calc(&self, x1: usize, x2: usize) -> usize;
}

#[derive(Default)]
pub struct Child;

#[async_trait]
impl Calc for Child {
    async fn calc(&self, x1: usize, x2: usize) -> usize {
        x1 + x2
    }
}


#[derive(Delegate, Default)]
#[to(Calc)]
pub struct Parent(Child);

#[tokio::main]
async fn main() {
    let mut parent = Parent::default();

    println!("{}",  parent.calc(3, 2).await)
}

v0.0.2

Choose a tag to compare

@not-elm not-elm released this 20 May 10:49

Supported New-Type Pattern

Example are as follows

#[delegate]
pub trait Calc {
    fn calc(&self, x1: usize, x2: usize) -> usize;
}


#[derive(Default)]
pub struct Child;


impl Calc for Child {
    fn calc(&self, x1: usize, x2: usize) -> usize {
        x1 + x2
    }
}


#[derive(Delegate, Default)]
#[to(Calc)]
pub struct Parent(Child);


fn main() {
    let mut parent = Parent::default();

    assert_eq!(parent.calc(2, 3), 5);
}