Hi, I tried to write a From trait to accept String, &str, and unsigned types. But compile failed. Any suggestion? Thanks!
pub struct Luhn {
data: String,
}
impl<T> From<T> for Luhn {
fn from(input: T) -> Self {
Luhn {
data: input.to_string(),
}
}
}
fn main () {
let l1 = Luhn::from("123");
let l2 = Luhn::from("123".to_string());
let l3 = Luhn::from(123_u32);
let l4 = Luhn::from(123_u16);
let l5 = Luhn::from(123_u8);
}
error[E0119]: conflicting implementations of trait `std::convert::From<Luhn>` for type `Luhn`:
--> src\main.rs:5:1
|
5 | impl<T> From<T> for Luhn {
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T> From<T> for T;