I have the following pair of implementations (playground link):
pub struct Foo<T> {it: T}
impl<T: IntoIterator> From<T> for Foo<T::IntoIter> {
fn from(x: T) -> Foo<T::IntoIter> {
Foo { it: x.into_iter() }
}
}
use std::str::Chars;
impl From<&'static str> for Foo<Chars<'static>> {
fn from(x: &'static str) -> Foo<Chars<'static>> {
Foo { it: x.chars() }
}
}
I'm getting a conflicting implementations error
and I don't understand why. As far as I can tell, the first generic impl cannot cover From<&'static str>
, since &str
does not implement IntoIterator
.
Is the compiler not smart enough to figure out this? Is there a reason this should not be allowed (say, an esoteric orphan rule)? Is there a way around it?