Implement the Default
Trait Along with new()
Sources:
https://rust-lang.github.io/rust-clippy/master/#new_without_default
https://rust-unofficial.github.io/patterns/idioms/default.html
The user of your type might expect to be able to use Default
. It is also more convenient for you.
#![allow(unused)] fn main() { struct Ex { field1: i32, field2: i32, } impl Ex { fn new() -> Self { Ex { field1: 0, field2: 0, } } } impl std::default::Default for Ex { fn default() -> Self { Ex::new() } } }