- new
The new method has no special feature
- We could use any other name instead of new. For example we could use qqrq as well.
- The name new is only to give the power of familiarity.
examples/struct/constructor/src/main.rs
#[derive(Debug)] #[allow(dead_code)] struct Something { name: String, number: i32, } impl Something { pub fn qqrq() -> Something { Something { name: "".to_string(), number: 0, } } } fn main() { let sg = Something { name: "Foo Bar".to_string(), number: 42, }; dbg!(sg); let new = Something::qqrq(); dbg!(new); }