Tracks
/
Rust
Rust
/
Exercises
/
Health Statistics
Health Statistics

Health Statistics

Learning Exercise

While completing Health Statistics, you'll learn 1 concept

Instructions

You're working on implementing a health-monitoring system. As part of that, you need to keep track of users' health statistics.

You'll start with some stubbed functions in an impl block as well as the following struct definition:

pub struct User {
    name: String,
    age: u32,
    weight: f32,
}

Your goal is to implement the stubbed out methods on the User struct defined in the impl block.

For example, the new method should return an instance of the User struct with the specified name, age, and weight values.

let mut bob = User::new(String::from("Bob"), 32, 155.2);
// Returns: a User with name "Bob", age 32, and weight 155.2

The weight method should return the weight of the User.

bob.weight();
// Returns: 155.2

The set_age method should set the age of the User.

bob.set_age(33);
// Updates Bob's age to 33; happy birthday Bob!

Have fun!

Last updated 13 September 2021
Edit via GitHub The link opens in a new window or tab
Rust Exercism

Ready to start Health Statistics?

Sign up to Exercism to learn and master Rust with 8 concepts, 102 exercises, and real human mentoring, all for free.