In the TryFrom section, is it worth mentioning that you cannot implement both From and TryFrom since if From is implemented for a given type T, an infallible TryFrom is also auto-implemented for you. Therefore you end up with conflicting trait implementations for the same type. For example, let's say you implement both From and TryFrom for Point, you get the following error:
error[E0119]: conflicting implementations of trait `TryFrom<(i32, i32)>` for type `Point`
--> src/main.rs:22:1
|
22 | impl TryFrom<(i32, i32)> for Point {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T, U> TryFrom<U> for T
where U: Into<T>;
For more information about this error, try `rustc --explain E0119`.
error: could not compile `foo` due to previous error
In the
TryFrom
section, is it worth mentioning that you cannot implement bothFrom
andTryFrom
since ifFrom
is implemented for a given type T, an infallibleTryFrom
is also auto-implemented for you. Therefore you end up with conflicting trait implementations for the same type. For example, let's say you implement bothFrom
andTryFrom
forPoint
, you get the following error: