I'm trying to get around coherence, and running into conflicting impls! In effect, I want to implement FromStr
for Option<MyType>
. That goes against the orphan check, so I defined my own local trait MyFromStr
, with a blanket impl for types that implement FromStr
.
Code is below. I'm a bit confused about how the blanket impl conflicts, as FromStr
isn't defined for Option
. What am I missing?
use std::str;
trait MyFromStr: Sized + str::FromStr {
type Err;
fn my_from_str(s: &str) -> Result<Self, <Self as MyFromStr>::Err>;
}
impl<T, E> MyFromStr for T
where T: str::FromStr<Err = E>
{
type Err = E;
fn my_from_str(s: &str) -> Result<T, E> {
str::FromStr::from_str(s)
}
}
struct MyType;
impl MyFromStr for Option<MyType> {
type Err = ();
fn my_from_str(s: &str) -> Result<Self, ()> {
unimplemented!();
}
}