Hello,
I have the following code (Rust Playground):
use std::convert::{From,Into};
#[derive(Debug)]
pub struct Modulo<T>(T);
impl<T> From<T> for Modulo<T> {
fn from(x: T) -> Self { Modulo(x) }
}
impl<T> Into<T> for Modulo<T> {
fn into(self) -> T { self.0 }
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn modulo_new() {
let x = Modulo(42);
assert_eq!(42, x.into());
}
}
And what I see when do cargo test
is
error: conflicting implementations of trait `std::convert::Into<_>` for type `utils::Modulo<_>`: [E0119]
I wounder who could implement Into
for my custom type? The error message says that it is core
who has alternative implementation.
However, when I drop my Into
implementation I see that no suitable Into
implementation is found:
error: the trait bound `i32: std::convert::From<utils::Modulo<i32>>` is not satisfied [E0277]
assert_eq!(42, x.into());