Implement new()
Source: https://rust-unofficial.github.io/patterns/idioms/ctor.html?highlight=construc#constructors
Rust's convention for constructing a new object is via new()
. When you define your own type,
implement new()
that creates a new instance.
#![allow(unused)] fn main() { struct Ex { field1: i32, field2: i32, } impl Ex { fn new() -> Self { Ex { field1: 0, field2: 0, } } } }