From 70efef4f385eeddb08769c95521b9299a26a1114 Mon Sep 17 00:00:00 2001 From: Martin Huschenbett Date: Wed, 6 Dec 2023 15:08:56 +0100 Subject: [PATCH] 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. --- src/methods-and-traits/methods.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/methods-and-traits/methods.md b/src/methods-and-traits/methods.md index 702d40c5..b78b42ed 100644 --- a/src/methods-and-traits/methods.md +++ b/src/methods-and-traits/methods.md @@ -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