[rust-dev] Deriving keyword

Huon Wilson dbau.pp at gmail.com
Thu Jan 23 20:38:58 PST 2014


On 24/01/14 15:32, benjamin adamson wrote:
> Question, what constitutes whether a 'trait' is applicable for 
> implementation by the #deriving() attribute?
>
> According to the language specification on master:
> http://static.rust-lang.org/doc/master/rust.html#deriving
>
> There exists a static list. I found myself interested in the idea of 
> using the deriving attribute to derive a simple drawable implementation:
>
> https://github.com/JeremyLetang/rust-sfml/blob/master/src/rsfml/traits/drawable.rs
>
> but then looked up the attribute in the rust manual, and noticed that 
> there is a static list of what I will call 'traits that support the 
> deriving attribute'. Why the restriction? Is there some prior reading 
> on this? Is there any plan on letting libraries define more types that 
> can be 'derivable'?
>
>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev

There's a static list because they're currently hard-coded into the 
compiler.

With external syntax extensions, it's now possible to define something 
like `#[deriving_Drawable]`, and, iirc, I left the core deriving 
infrastructure public in syntax::ext::deriving::generic, so you can get 
most of the work done for you that way.


There are various things to be worked out for adding traits directly to 
#[deriving(Foo)], including (but not limited to) how namespacing works 
(e.g. if two libraries both define a trait with the same name and 
provide #[deriving] implementations for it), and whether we want it to 
be a priviledged syntax extension where users can directly add to its 
map between traits and deriving implementation.


Huon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140124/6c695ef8/attachment-0001.html>


More information about the Rust-dev mailing list