Skip to content

Commit c42cb82

Browse files
authored
health-statistics: name setters set_foo, not foo_mut (#1582)
This reverts commit 6e46786. By the conventions expressed in https://github.com/rust-lang/rfcs/blob/master/text/0344-conventions-galore.md#gettersetter-apis a setter for `foo` must be named `set_foo`. Methods named `_mut` by convention return `&mut`, and neither `age_mut` nor `weight_mut` do that. Therefore to name them `_mut` violates convention. We should not violate convention.
1 parent 7e6e525 commit c42cb82

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

exercises/concept/health-statistics/.docs/hints.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ fn foo() -> i32 {
2626

2727
## 3. Implement the setter methods
2828

29-
- The `age_mut()` and `weight_mut()` methods are setters, responsible for mutating (updating) the corresponding field on a struct instance with the input argument.
29+
- The `set_age()` and `set_weight()` methods are setters, responsible for updating the corresponding field on a struct instance with the input argument.
3030

3131
- As the signatures of these methods specify, the setter methods shouldn't return anything.

exercises/concept/health-statistics/.docs/instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ bob.weight();
2828
// Returns: 155.2
2929
```
3030

31-
The `age_mut` method should set the age of the `User`.
31+
The `set_age` method should set the age of the `User`.
3232

3333
```rust
34-
bob.age_mut(33);
34+
bob.set_age(33);
3535
// Updates Bob's age to 33; happy birthday Bob!
3636
```
3737

exercises/concept/health-statistics/.meta/exemplar.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ impl User {
2121
self.weight
2222
}
2323

24-
pub fn age_mut(&mut self, new_age: u32) {
24+
pub fn set_age(&mut self, new_age: u32) {
2525
self.age = new_age;
2626
}
2727

28-
pub fn weight_mut(&mut self, new_weight: f32) {
28+
pub fn set_weight(&mut self, new_weight: f32) {
2929
self.weight = new_weight;
3030
}
3131
}

exercises/concept/health-statistics/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ impl User {
2525
unimplemented!()
2626
}
2727

28-
pub fn age_mut(&mut self, new_age: u32) {
28+
pub fn set_age(&mut self, new_age: u32) {
2929
unimplemented!()
3030
}
3131

32-
pub fn weight_mut(&mut self, new_weight: f32) {
32+
pub fn set_weight(&mut self, new_weight: f32) {
3333
unimplemented!()
3434
}
3535
}

exercises/concept/health-statistics/tests/health-statistics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn test_weight() {
2929
fn test_set_age() {
3030
let new_age: u32 = 90;
3131
let mut user = User::new(NAME.into(), AGE, WEIGHT);
32-
user.age_mut(new_age);
32+
user.set_age(new_age);
3333
assert_eq!(user.age(), new_age);
3434
}
3535

@@ -38,6 +38,6 @@ fn test_set_age() {
3838
fn test_set_weight() {
3939
let new_weight: f32 = 129.4;
4040
let mut user = User::new(NAME.into(), AGE, WEIGHT);
41-
user.weight_mut(new_weight);
41+
user.set_weight(new_weight);
4242
assert!((user.weight() - new_weight).abs() < f32::EPSILON);
4343
}

0 commit comments

Comments
 (0)