You don't. The entire reason that the RFC exists is because it wasn't possible before!
As "proof", consider str::to_string
. Before specialization existed, str::to_string
used the exact same mechanism as all the other implementors of ToString
, which meant that it had to build up and use the formatting infrastructure. This is relatively expensive and benchmarks actively showed the difference between str::to_string
and str::to_owned
or String::from
. After specialization was enabled, the Rust compiler used it for str::to_string
, and the benchmarks improved.
If the Rust compiler couldn't specialize before specialization, it's highly unlikely that other code could find some way to work around it in a generic manner.
For your specific case, I agree that you should just accept something implementing BufRead
(fn read<T: BufRead>(stream: T)
).