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