- Correctly pass generic method type and lifetime arguments to the delegated method.
- Generalize match arms handling. You can now combine a match expression target with annotations like
#[into]
and others:
struct A;
impl A {
pub fn callable(self) -> Self {
self
}
}
struct B;
impl B {
pub fn callable(self) -> Self {
self
}
}
enum Common {
A(A),
B(B),
}
impl From<A> for Common {
fn from(inner: A) -> Self {
Self::A(inner)
}
}
impl From<B> for Common {
fn from(inner: B) -> Self {
Self::B(inner)
}
}
impl Common {
delegate! {
to match self {
// ---------- `match` arms have incompatible types
Common::A(inner) => inner;
Common::B(inner) => inner;
} {
#[into]
pub fn callable(self) -> Self;
}
}
// Generates
// pub fn callable(self) -> Self {
// match self {
// Common::A(inner) => inner.callable().into(),
// Common::B(inner) => inner.callable().into(),
// }
// }
}
- The crate should be
#[no_std]
compatible again (#74).
-
Add new
#[newtype]
function parameter modifier (#64). Implemented by Techassi -
Allow passing arbitrary attributes to delegation segments:
impl Foo {
delegate! {
#[inline(always)]
to self.0 { ... }
}
}
- Change the default inlining mode from
#[inline(always)]
to#[inline]
(#61).
- Allow delegating an associated function (not just a method).
struct A {}
impl A {
fn foo(a: u32) -> u32 {
a + 1
}
}
struct B;
impl B {
delegate! {
to A {
fn foo(a: u32) -> u32;
}
}
}
- Allow specifying certain attributes (e.g.
#[into]
or#[unwrap]
) on delegated segments. The attribute will then be applied to all methods in that segment (unless it is overwritten on the method itself).
delegate! {
#[unwrap]
to self.inner {
fn foo(&self) -> u32; // calls self.inner.foo().unwrap()
fn bar(&self) -> u32; // calls self.inner.bar().unwrap()
}
}
- Add new
#[unwrap]
method modifier. Adding it on top of a delegated method will cause the generated code to.unwrap()
the result.
#[unwrap]
fn foo(&self) -> u32; // foo().unwrap()
- Add new
#[through(<trait>)]
method modifier. Adding it on top of a delegated method will cause the generated code to call the method through the provided trait using UFCS.
#[through(MyTrait)]
delegate! {
to &self.inner {
#[through(MyTrait)]
fn foo(&self) -> u32; // MyTrait::foo(&self.inner)
}
}
- Removed
#[try_into(unwrap)]
. It can now be replaced with the combination of#[try_into]
and#[unwrap]
:
#[try_into]
#[unwrap]
fn foo(&self) -> u32; // TryInto::try_into(foo()).unwrap()
- Add the option to specify explicit type path to the
#[into]
expression modifier:
#[into(u64)]
fn foo(&self) -> u64; // Into::<u64>::into(foo())
- Expression modifiers
#[into]
,#[try_into]
and#[unwrap]
can now be used multiple times. The order of their usage dictates in what order they will be applied:
#[into]
#[unwrap]
fn foo(&self) -> u32; // Into::into(foo()).unwrap()
#[unwrap]
#[into]
fn foo(&self) -> u32; // Into::into(foo().unwrap())
- Add new
#[as_ref]
function parameter modifier (#47). Implemented by trueegorletov.
- Add new
#[into]
attribute for delegated function parameters. If specified, the parameter will be converted using theFrom
trait before being passed as an argument to the called function. - Add new
#[try_from]
attribute to delegated functions. You can use it to convert the delegated expression using theTryFrom
trait. You can also use#[try_from(unwrap)]
to unwrap the result of the conversion.
- Add new
#[await(true/false)]
attribute to delegated functions. You can use it to control whether.await
will be appended to the delegated expression. It will be generated by default if the delegation method signature isasync
.
- add support for
async
functions. The delegated call will now use.await
.
- add the option to specify inline expressions that will be used as arguments for the delegated call (#34)
- removed
append_args
attribute, which is superseded by the mentioned expression in signature support
- add the
append_args
attribute to append attributes to delegated calls (#31)
- fix breaking change caused by using
syn
private API (#28)
self
can now be used as the delegation target- Rust 1.46 introduced a change that makes it a bit difficult to use
rust-delegate
implementations generated by macros. If you have this use case, please use this workaround.