Implementing Sub trait for slices
<p>Is it possible to implement the <code>std::ops::Sub</code> trait for slices in Rust? And if so how would I do that?</p>

<p>I tried the following: </p>

<pre><code>use std::ops::Sub;

impl &lt;'a, 'b, T&gt; Sub&lt;&amp;'a [T]&gt; for &amp;'b [T] {
    type Output = Vec&lt;T&gt;;
    fn sub(self, rhs: &amp;[T]) -&gt; Vec&lt;T&gt; {
        difference(self, rhs)
    }
}
</code></pre>

<p>with <code>difference</code> having the signature:</p>

<pre><code>difference&lt;T: PartialEq + Copy&gt;(xs: &amp;[T], ys: &amp;[T]) -&gt; Vec&lt;T&gt;
</code></pre>

<p>compiling it results in the following error message:</p>

<pre><code>error: type parameter `T` must be used as the type parameter for some local type 
    (e.g. `MyStruct&lt;T&gt;`); only traits defined in the current crate 
    can be implemented for a type parameter [E0210]
impl &lt;'a, 'b, T&gt; Sub&lt;&amp;'a [T]&gt; for &amp;'b [T] {
^
</code></pre>

<p>running then <code>rust --explain E0210</code> to get further information I can kinda understand the problem, but I am confused about how the syntax would look like when using the <code>struct MyType&lt;T&gt;(T);</code> workaround described in the detailed explanation.</p>

<p>In difference to the question found <a href="https://stackoverflow.com/questions/25413201/how-do-i-implement-a-trait-i-dont-own-for-a-type-i-dont-own">How do I implement a trait I don't own for a type I don't own?</a> my problem is I do not want this for vector types, but for slice types for which the syntax seems to be different enough that this answer is not really helpful.</p>