[rust-dev] Traits proposal

Stefan Plantikow stefan.plantikow at googlemail.com
Sat Jul 14 04:39:56 PDT 2012

On 14 Jul 2012, at 13:12, David Bruant wrote:

> Hi,
> I'd like to bring a bit more of feedback. I've read Stateful Traits 
> [1]
> and I was wondering how Rust intended to solve the issue mentionned in
> the paper related to statelessness:
> "However this simple model suffers from several limitations, in 
> particular
> (i) trait reusability is impacted because the required interface is
> typically cluttered with uninteresting required accessors,
> (ii) client classes are forced to implement boilerplate glue code,
> (iii) the introduction of new state in a trait propagates required
> accessors to all client classes,
> (iv) public accessors break encapsulation of the client class."

Haven't read the paper but think such things can be circumvented with 
support for delegation quite nicely, somewhat similar to what go does.

The idea is to have a syntax feature which allows to automatically 
redirect some calls to a member field.
So instead of mixing in a trait with all state accessors one would 
delegate only the methods required by the interface type to a member 
field or a derived value.  This would give a nice way to provide 
encapsulation and export only required interface calls without having to 
write all the boilerplate delegation methods.

At some point I wrote a very rough syntax proposal for this in the Wiki 
but it's likely outdated now. If there would be interest for this, I'd 
try to come up with a new one. Basically what is needed is a way for 
specifying how to extract a value that implements an interface from self 
and some support for overwriting the derived methods and dealing with 
conflicts.  One can also understand this as a mechanism for 
user-provided type conversion that is integrated with the type class 



More information about the Rust-dev mailing list