Hello there,
I am aware that the specialization feature is still unstable, but I was wondering if there was a way to circumvent my problem.
Here, I would like to implement two specializations of Convert
: one for String
and one for &str
.
While the former works very well, the latter does not compile. Do you know if there is any way such that I could manage to implement Convert
for &str
specifically?
Thanks in advance!
MWE:
#![feature(min_specialization)]
trait Convert<'source> {
fn convert(src: &'source str) -> Self;
}
impl<'source, T> Convert<'source> for T
where T:
From<&'source str>
{
default fn convert(src: &'source str) -> Self {
src.into()
}
}
impl<'source> Convert<'source> for String {
default fn convert(src: &'source str) -> Self {
src.into()
}
}
impl<'source> Convert<'source> for &'source str {
default fn convert(src: &'source str) -> Self {
src.into()
}
}
fn main() {
println!("Hello");
}
Errors:
Compiling playground v0.0.1 (/playground)
error: specializing impl repeats parameter `'source`
--> src/main.rs:22:1
|
22 | impl<'source> Convert<'source> for &'source str {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: could not compile `playground` due to previous error