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.
nprimo
f99f57537f
|
2 years ago | |
---|---|---|
.. | ||
README.md | 2 years ago |
README.md
dress_code
Instructions
Create a function called choose_outfit
that receives the following input:
- a
formality_level
as anOption<u32>
; - an
invitation_message
as aResult<&str>
.
The function will return a struct Outfit
which contains:
jacket
, anenum
Jacket
that containsBlack
,White
andFlowers
;- 'hat', an
enum
Hat
that containsSnapback
,Baseball
,Fedora
.
#[derive(Debug, PartialEq, Eq)]
pub struct Outfit {
pub jacket: Jacket,
pub hat: Hat,
}
For the jacket
:
- the jacket should be
Flowers
when theformality_level
is unset; - the jacket should be
White
when theformality_level
is more than 0; - otherwise it should be
Black
.
For the hat
:
- if the
invitation_message
isOk()
it should beFedora
; - otherwise it should be
Snapback
.
In the specific case where formality_level
is None
and invitation_message
is not Ok()
then the jacket
should be Flowers
and the hat
should be Baseball
.
Remember that all the enum
and struct
used must be pub
.
Expected functions
pub fn choose_outfit(formality_level: Option<u32>, invitation_message: Result<&str>) -> Outfit {}
Usage
Here is a program to test your function.
use dress_code::*;
fn main() {
println!("My outfit will be: {:?}", choose_outfit(Some(0), Ok("Dear friend, ...")));
}
And its output:
$ cargo run
My outfit will be: Outfit { jacket: Black, hat: Fedora }
...