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

19 lines
284 B
Rust
Raw Normal View History

2023-09-26 10:07:51 +00:00
use std::convert::From;
#[allow(dead_code)]
#[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);
}