In the following code:
enum Either<A, B> { Left(A), Right(B) }
use Either::{Left, Right};
impl<A, B> From<A> for Either<A, B> {
fn from(a: A) -> Self {
Left(a)
}
}
impl<A, B> From<B> for Either<A, B> {
fn from(b: B) -> Self {
Right(b)
}
}
I'm getting the following error: "conflicting implementations of trait std::convert::From<_> for type Either<_, _>". I do not understand how the implementation of From<A> and From<B> for Either<A, B> is conflicting.
I saw an example in the standard library docs where they're doing almost exactly what I'm doing but it works there:
use std::fs;
use std::io;
use std::num;
enum CliError {
IoError(io::Error),
ParseError(num::ParseIntError),
}
impl From<io::Error> for CliError {
fn from(error: io::Error) -> Self {
CliError::IoError(error)
}
}
impl From<num::ParseIntError> for CliError {
fn from(error: num::ParseIntError) -> Self {
CliError::ParseError(error)
}
}
Please can someone explain? Thanks.