The doc says users should only implement either From or Into, preferably From. And I assume how that works is if you implement one, the compiler will automatically do the other one for you behind the scene.
But the following testing code suggests that's not the case. So my question is, is it a bug with the compiler? Or is this behavior by design, and I misunderstood the doc.
Thanks in advance.
#[test]
fn generic_convert_from() {
struct MyBool {
inner: bool,
}
impl std::convert::From<u32> for MyBool {
fn from(s: u32) -> Self {
Self { inner: s > 0 }
}
}
fn test_fn<T>(src: T) -> MyBool
where
// T: std::convert::Into<MyBool>, // This does not work
MyBool: std::convert::From<T>, // This works
{
MyBool::from(src)
}
test_fn(123u32);
}
Error message:
error[E0277]: the trait bound `feature_type::generic_convert_from::MyBool: std::convert::From<T>` is not satisfied
--> src/feature_type/mod.rs:327:9
|
327 | MyBool::from(src)
| ^^^^^^^^^^^^ the trait `std::convert::From<T>` is not implemented for `feature_type::generic_convert_from::MyBool`
|
= note: required by `std::convert::From::from`
$ rustc --version
rustc 1.43.0-nightly (564758c4c 2020-03-08)