Suppose I have the following type:
#[derive(Default)] struct Foo(pub i32); // public Since it's a tuple with a public member, any conversions from/to i32 can simply be made using the 0 member:
let foo = Foo::default(); let num: i32 = foo.0; // Foo to i32 let goo = Foo(123); // i32 to Foo Now I want to make the 0 member non-public, implementing From trait:
#[derive(Default)] struct Foo(i32); // non-public impl From<i32> for Foo { fn from(n: i32) -> Foo { Foo(n) } } But the conversion fails from i32 to Foo:
let foo = ay::Foo::default(); let num: i32 = foo.into(); // error! let goo = ay::Foo::from(123); // okay What's the correct way to implement this bidirectional conversion? Rust playground here.