Implement something similar to C++'s `std::remove_reference` in Rust? : <p>I'd like to have a tool to remove the reference from a type if the type is a reference. Something like this (pseudo code):</p>

<pre><code>remove_ref(i32)      == i32
remove_ref(&amp;i32)     == i32
remove_ref(&amp;&amp;i32)    == i32
remove_ref(&amp;mut i32) == i32
</code></pre>

<p>C++ has <a href="http://www.cplusplus.com/reference/type_traits/remove_reference/" rel="noreferrer"><code>std::remove_reference</code></a> in the standard library which can do exactly what I want. I tried to implement the same in Rust, but I can't get it working. Right now, the only way to "output" types in Rust are associated types on traits (I think). I tried something like this (<a href="https://play.rust-lang.org/?gist=1d77c235aaefd325612ff742029bbc3b&amp;version=nightly&amp;mode=debug" rel="noreferrer">Playground</a>):</p>

<pre><code>#![feature(specialization)]

trait RemoveRef {
    type WithoutRef;
}

default impl&lt;T&gt; RemoveRef for T {
    type WithoutRef = T;
}

impl&lt;'a, T: RemoveRef&gt; RemoveRef for &amp;'a T {
    type WithoutRef = T::WithoutRef;
}
</code></pre>

<p>And in fact this compiles. Promising! (yes, this doesn't account for mutable references yet). However, everything explodes when I try to use it:</p>

<pre><code>let _: &lt;i32 as RemoveRef&gt;::WithoutRef = 3;
let _: &lt;&amp;i32 as RemoveRef&gt;::WithoutRef = 3;
let _: &lt;&amp;&amp;i32 as RemoveRef&gt;::WithoutRef = 3;
</code></pre>

<p>The first line leads to "overflow evaluating the requirement <code>i32: RemoveRef</code>". The other two lines produce the error "the trait bound <code>&amp;i32: RemoveRef</code> is not satisfied". I'm not sure if I just don't understand this or if specialization is broken. (Related: I got another strange error with very similar code <a href="https://stackoverflow.com/questions/51022636/mismatch-between-associated-type-and-type-parameter-only-when-impl-is-marked-de">here</a>)</p>

<p>I was thinking about other possibilities to implement this: maybe put a type parameter on the trait? Maybe GATs could help here? Are there other features in the language that allow mapping from one type to another type?</p>

<p><strong>Is there any way to implement something like this in Rust?</strong></p>
