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.
miguel
166a10990f
|
1 year ago | |
---|---|---|
.. | ||
README.md | 2 years ago | |
main.rs | 1 year 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
, anenum
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, &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 }
$