0

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?

rvidal
  • 2,012
  • 1
  • 17
  • 24
  • *since `&str` does not implement `IntoIterator`* — it doesn't now, but the standard library is free to do so in the future. – Shepmaster Nov 04 '17 at 15:05
  • I highly encourage you to search for duplicates next time — the two I've linked were pretty easy to find for the search term "conflicting implementations of trait from". – Shepmaster Nov 04 '17 at 15:08

0 Answers0