How to use specialization features


#1

I am keen to use the new specialization features of Rust, but can’t find any documentation on it yet. In particular I would like something like this to work:

struct Special
{
    x : usize,
    y : usize
}

trait MyTrait
{
    fn myfunc(&self);
}

impl<T> MyTrait for T
{
    fn myfunc(&self) { println!("hi"); }
}

impl MyTrait for Special
{
    fn myfunc(&self) { println!("I'm special"); }
}

The compiler complains about duplicate definitions. Is there any way to make this work?

Steve


#2

Specialization is currently only used in the standard library and is still a nightly feature. Also, functions that can be specialized need to be marked as “default”

See https://is.gd/xk020b for a working example.


#3

I also use it in the support library for overflower (alas, the plugin itself isn’t finished yet).


#4

The only ‘official’ documentation so far is the RFC:


#5

In general, since there is so much doc work to do, I don’t write much
documentation for unstable things, as it might change and need to be
re-done by the time it’s stable.


#6

Thanks, with the default keyword it works great.