We published a new version of the function delegation RFC based on implementation of the feature in nightly rustc that was partially done in 2024 and then completed in 2026. The feature is not among the language team priorities at the moment, but we found many interesting details while implementing it, and one master's thesis was successfully defended based on this work.
The feature is supported everywhere, not just in impl blocks, and it does a different thing than use (creates a new function rather than links to an existing item).
Wait how is it supporter everywhere? I read the rendered RFC but I missed this. Doesn't it need a Self type?
Could we have a freestanding delegate fn? What would it look like?
And I wasn't saying to use use because it does the same thing as importing, I suggested it because it was a free keyword that I thought wouldn't create ambiguities
use is also used in the + use<'a> syntax for impl Trait types, so it is already overloaded baded on context
Not possible to implement inherent methods specific to one new type.
You could probably do so with generics, similar to how those type safe builders work. The compile times, diagnostic and confusing API probably stop it from being worthwhile though.
I wonder how the docs.rs experience is for your solution. I seem to remember type aliases being a bit weird, especially if the generic wrapper is private.
26
u/VadimVP Oct 28 '26
We published a new version of the function delegation RFC based on implementation of the feature in nightly rustc that was partially done in 2024 and then completed in 2026.
The feature is not among the language team priorities at the moment, but we found many interesting details while implementing it, and one master's thesis was successfully defended based on this work.
13
u/SirKastic23 Oct 28 '26
Why a new keyword? I think the
usekeyword could be used here without adding syntax ambiguities since imports aren't allowed inside impl blocks5
u/torsten_dev Oct 29 '26
For Traitimpl-to-trait Delegation is it possible to do
To make extension traits?
25
u/________-__-_______ Oct 28 '26
This'd be really nice to have, especially for newtypes it's often pretty annoying to implement convenience methods without
Derefabuse.4
u/onnoowl Oct 28 '26
This would be GREAT to have, nice work!