Default, From and Into
Default gives a standard value. From and Into convert between types.
Example
#[derive(Debug, Default)]
struct Config { port: u16, debug: bool }
fn main() {
let c = Config::default();
let n: i64 = i64::from(5_i32);
let s: String = "hi".into();
println!("{:?} {} {}", c, n, s);
}Result
Config { port: 0, debug: false } 5 hiExercise
Standard value.
#[derive()]
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.