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 program