box-o-sand/rustbyexample/conversion.d/from_into2.rs

20 lines
300 B
Rust
Raw Normal View History

2023-09-26 10:07:51 +00:00
use std::convert::Into;
#[allow(dead_code)]
#[derive(Debug)]
struct Number {
value: i32,
}
impl Into<Number> for i32 {
fn into(self) -> Number {
Number { value: self }
}
}
fn main() {
let int = 5;
let num: Number = int.into();
println!("My number is {:?}", num);
}