I’ve suggested a new enhancement request:
https://github.com/rust-lang/rust/issues/42601
An example usage:
struct VecA { x: u32, y: u32 }
impl VecA {
fn new() -> Self {
Self { x: 0, y: 0 } // OK
}
}
struct VecB(u32, u32);
impl VecB {
fn new() -> Self {
Self(0, 0) // Error
}
}
fn main() {}
The current error message is:
error[E0423]: expected function, found self type `Self`
--> ...\test.rs:10:9
|
10 | Self(0, 0) // Error
| ^^^^ did you mean `Self { /* fields */ }`?
The use of “Self(0, 0)” looks symmetrical with the “Self { x: 0, y: 0 }” syntax, and it allows to write code a little more DRY.