In this challenge, you will use Rust's pattern matching capabilities to determine the name of a weekday given its corresponding number. Each day of the week will be represented by a number from 1 to 7, where 1 corresponds to Monday and 7 corresponds to Sunday.
This is a common task that can be very useful in various applications, such as scheduling systems or calendar utilities. You will practice working with Rust's match
statement to map numbers to their respective weekdays.
Your task is to implement a function, weekday_from_number(day: u8) -> &'static str
, that takes a number as input and returns the corresponding weekday as a string. If the input number is not within the range of 1 to 7, the function should return "Invalid day number".
match
statement to map each number to its corresponding weekday.&'static str
denotes a string slice that lives for the entire duration of the programwoke-developer
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number", }}
mbergkvist
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }}
5822791760
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number", }}
leenalmajz
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here if day == 1 { return "Monday" } else if day == 2 { return "Tuesday" } else if day == 3 { return "Wednesday" } else if day == 4 { return "Thursday" } else if day == 5 { return "Friday" } else if day == 6 { return "Saturday" } else if day == 7 { return "Sunday" } else { return "Invalid day number" }}
facat
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day{ 1=>"Monday", 2=>"Tuesday", 3=>"Wednesday", 4=>"Thursday", 5=>"Friday", 6=>"Saturday", 7=>"Sunday", _=>"Invalid day number" }}
xenonminer
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }}
XtebanUy
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }}
StimhackSoftware
pub fn weekday_from_number(day: u8) -> &'static str { match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _x => "Invalid day number", }}
mehdihmr
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day{ 1 => return "Monday", 2 => return "Tuesday", 3 => return "Wednesday", 4 => return "Thursday", 5 => return "Friday", 6 => return "Saturday", 7 => return "Sunday", _ => return "Invalid day number" }}
MisterWoody
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here let day_name = match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number", }; day_name}
ethel-dev
pub fn weekday_from_number(day: u8) -> &'static str { match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }}
DivineGod
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number", }}
Algorab
pub fn weekday_from_number(day: u8) -> &'static str { match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }}
penscola
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }}
itaygenkin
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => return "Monday", 2 => return "Tuesday", 3 => return "Wednesday", 4 => return "Thursday", 5 => return "Friday", 6 => return "Saturday", 7 => return "Sunday", _ => return "Invalid day number", }}
sroas
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number", }}
felipebalbi
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number", }}
danielmpetrov
pub fn weekday_from_number(day: u8) -> &'static str { match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number", }}
chuyuanlinzi
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number", }}
yoakemae
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here return match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number", }}
qiyuan711
pub fn weekday_from_number(day: u8) -> &'static str { match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number", }}
jw
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number", }}
nickythorne
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => return "Monday", 2 => return "Tuesday", 3 => return "Wednesday", 4 => return "Thursday", 5 => return "Friday", 6 => return "Saturday", 7 => return "Sunday", _ => return "Invalid day number" };}
DV-13
pub fn weekday_from_number(day: u8) -> &'static str { match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number", }}
DV-13
pub fn weekday_from_number(day: u8) -> &'static str { match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number", }}
tinthid
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here let weekday: Vec<&str> = vec!["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]; if day < 1 || day > 7 { return "Invalid day number"; } weekday[(day - 1) as usize]}
martin-unit
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => return "Monday", 2 => return "Tuesday", 3 => return "Wednesday", 4 => return "Thursday", 5 => return "Friday", 6 => return "Saturday", 7 => return "Sunday", _ => return "Invalid day number" }}
RonaldoArayadev
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => return "Monday", 2 => return "Tuesday", 3 => return "Wednesday", 4 => return "Thursday", 5 => return "Friday", 6 => return "Saturday", 7 => return "Sunday", _ => return "Invalid day number" }}
dalprahcd
pub fn weekday_from_number(day: u8) -> &'static str { match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number", }}
vrzwflng
pub fn weekday_from_number(day: u8) -> &'static str { match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }}
Thymelizabeth
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }}
tamanishi
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number", }}
devarajang
pub fn weekday_from_number(day: u8) -> &'static str { return match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" };}
nichideropa
pub fn weekday_from_number(day: u8) -> &'static str { // TODO => Implement the function here match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number", }}
akshayabhattarai
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here let mut res = match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }; return res}
jeypiti
pub fn weekday_from_number(day: u8) -> &'static str { match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }}
jeypiti
pub fn weekday_from_number(day: u8) -> &'static str { match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }}
oDqnger
pub fn weekday_from_number(day: u8) -> &'static str { match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number", }}
konishu
pub fn weekday_from_number(day: u8) -> &'static str { match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number", }}
0xsmarter
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }}
joeslow
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }}
joeslow
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }}
madeinheaven91
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day{ 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }}
t3stlab
pub fn weekday_from_number(day: u8) -> &'static str { match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }}
aidan1magee
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }}
ankeetparikh
pub fn weekday_from_number(day: u8) -> &'static str { // TODO: Implement the function here match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }}
38911BytesFree
pub fn weekday_from_number(day: u8) -> &'static str { match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }}
maxvi
pub fn weekday_from_number(day: u8) -> &'static str { match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number", }}
shinuza
pub fn weekday_from_number(day: u8) -> &'static str { match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }}
koslowskio
pub fn weekday_from_number(day: u8) -> &'static str { let result = match day { 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday", 7 => "Sunday", _ => "Invalid day number" }; return result}