You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-07-14 10:04:19 +02:00
Use Self to create struct in method chapter (#1559)
If I'm not mistaken, it's idomatic to use `Self` in a struct constructor rather than the name of the struct.
This commit is contained in:
committed by
GitHub
parent
6c5061bb90
commit
70efef4f38
@ -16,7 +16,7 @@ struct Race {
|
||||
|
||||
impl Race {
|
||||
fn new(name: &str) -> Self { // No receiver, a static method
|
||||
Race { name: String::from(name), laps: Vec::new() }
|
||||
Self { name: String::from(name), laps: Vec::new() }
|
||||
}
|
||||
|
||||
fn add_lap(&mut self, lap: i32) { // Exclusive borrowed read-write access to self
|
||||
|
Reference in New Issue
Block a user