From 9e5c318a57b2adca7f0da567d01a66effc67dd51 Mon Sep 17 00:00:00 2001 From: Martin Huschenbett Date: Fri, 17 Jan 2025 14:53:37 +0800 Subject: [PATCH] Fix minor inconsistencies and naming issues (#2563) --- src/iterators/iterator.md | 2 +- src/methods-and-traits/methods.md | 6 +++--- src/references/slices.md | 2 +- third_party/rust-on-exercism/health-statistics.rs | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/iterators/iterator.md b/src/iterators/iterator.md index 0d370794a587..bfc3a46c586f 100644 --- a/src/iterators/iterator.md +++ b/src/iterators/iterator.md @@ -29,7 +29,7 @@ impl<'s> Iterator for SliceIter<'s> { } fn main() { - let slice = [2, 4, 6, 8].as_slice(); + let slice = &[2, 4, 6, 8]; let iter = SliceIter { slice, i: 0 }; for elem in iter { println!("elem: {elem}"); diff --git a/src/methods-and-traits/methods.md b/src/methods-and-traits/methods.md index a49ad15f877b..974ed3c46475 100644 --- a/src/methods-and-traits/methods.md +++ b/src/methods-and-traits/methods.md @@ -9,12 +9,12 @@ Rust allows you to associate functions with your new types. You do this with an ```rust,editable #[derive(Debug)] -struct Race { +struct CarRace { name: String, laps: Vec, } -impl Race { +impl CarRace { // No receiver, a static method fn new(name: &str) -> Self { Self { name: String::from(name), laps: Vec::new() } @@ -41,7 +41,7 @@ impl Race { } fn main() { - let mut race = Race::new("Monaco Grand Prix"); + let mut race = CarRace::new("Monaco Grand Prix"); race.add_lap(70); race.add_lap(68); race.print_laps(); diff --git a/src/references/slices.md b/src/references/slices.md index bb4cb3cf54be..4ea60733621d 100644 --- a/src/references/slices.md +++ b/src/references/slices.md @@ -10,7 +10,7 @@ A slice gives you a view into a larger collection: ```rust,editable fn main() { - let mut a: [i32; 6] = [10, 20, 30, 40, 50, 60]; + let a: [i32; 6] = [10, 20, 30, 40, 50, 60]; println!("a: {a:?}"); let s: &[i32] = &a[2..4]; diff --git a/third_party/rust-on-exercism/health-statistics.rs b/third_party/rust-on-exercism/health-statistics.rs index b414e61a4032..a9ed8cdb10c8 100644 --- a/third_party/rust-on-exercism/health-statistics.rs +++ b/third_party/rust-on-exercism/health-statistics.rs @@ -6,7 +6,7 @@ pub struct User { name: String, age: u32, height: f32, - visit_count: usize, + visit_count: u32, last_blood_pressure: Option<(u32, u32)>, } @@ -35,7 +35,7 @@ impl User { let bp = measurements.blood_pressure; let report = HealthReport { patient_name: &self.name, - visit_count: self.visit_count as u32, + visit_count: self.visit_count, height_change: measurements.height - self.height, blood_pressure_change: match self.last_blood_pressure { Some(lbp) => {