Rust By ExampleのFrom and Intoが分かりにくい

The From and Into traits are inherently linked, and this is actually part of its implementation. If you are able to convert type A from type B, then it should be easy to believe that we should be able to convert type B to type A.

Rust By Exampleに上記が書いてあるので、型Aから型Bへの変換と、型Bから型Aへの変換の両方ができると誤解してしまった。

写経してみると、into()もfrom()もi32をNumberへ変換しているので同じじゃないかとなる。誰かが解説書いているだろと思い、探すとhttps://dackdive.hateblo.jp/entry/2021/04/30/100000が見つかり、やっぱりそうかと納得できた。

use std::convert::From;

#[derive(Debug)]
struct Number {
    value: i32,
}

impl From<i32> for Number {
    fn from(item: i32) -> Self {
        Number { value: item }
    }
}

fn main() {
    let num = Number::from(30);
    println!("My number is {:?}", num);
    let int: i32 = 5;
    let num: Number = int.into();
    println!("My number is {:?}", num);
}