Created
November 4, 2022 04:42
-
-
Save stegaBOB/cebca3d013758ccef69e7059467f5a6b to your computer and use it in GitHub Desktop.
Using Into to implement From builds and causes a stack overflow at runtime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Default, Debug)] | |
pub struct Bar { | |
pub bob: String, | |
} | |
#[derive(Default, Debug)] | |
pub struct Foo { | |
pub alice: u16, | |
} | |
impl From<Bar> for Foo { | |
fn from(bar_struct: Bar) -> Self { | |
Into::<Self>::into(bar_struct) | |
} | |
} | |
fn main() { | |
let new_bar = Bar::default(); | |
println!("New Bar: {:?}", new_bar); | |
let new_foo: Foo = new_bar.into(); | |
println!("New Foo: {:?}", new_foo); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: