mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
davhojt
4dbe8b5a8f
|
3 years ago | |
---|---|---|
.. | ||
README.md | 3 years ago |
README.md
changes
Instructions
Imagine you are working on some software to control smart lights in a house. You have access to an array of all the lights in that house.
Define the associated function new
, and add it to the data structure Light
. It should create a new light with the alias passed as an argument, with a brightness of .
Define the function change_brightness
, which receives a Vec
of lights, an alias
and a u8
value. It should find the light in the Vec
by its alias, and set the value of the brightness.
Expected Functions and Structure
#[derive(Debug, Eq, PartialEq, Clone)]
pub struct Light {
pub alias: String,
pub brightness: u8,
}
impl Light {
pub fn new(alias: &str) -> Self {
}
}
pub fn change_brightness(lights: &mut Vec<Light>, alias: &str, value: u8) {
}
Usage
Here is an incomplete program to test your function
use changes::*;
fn main() {
// bedroom
let mut lights = vec![
Light::new("living_room"),
Light::new("bedroom"),
Light::new("rest_room"),
];
println!("brightness = {}", lights[0].brightness);
change_brightness(&mut lights, "living_room", 200);
println!("new brightness = {}", lights[0].brightness);
}
And its expected output
$ cargo run
brightness = 0
new brightness = 200
$