How to use specialization features

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

1 Like

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 Rust Playground for a working example.

1 Like

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

The only 'official' documentation so far is the RFC:

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.

2 Likes

Thanks, with the default keyword it works great.