Enums, short for enumerations, are a type that limits all possible values of
some data. The possible values of an enum
are called variants. Enums also
work well with match
and other control flow operators to help you express
intent in your Cairo programs.
In this exercise you'll be generating semi-structured log messages.
You'll start with some stubbed functions and the following enum:
#[derive(Drop, Clone, PartialEq, Debug)]
pub enum LogLevel {
Info,
Warning,
Error,
Debug
}
Your goal is to emit a log message as follows: "[<LEVEL>]: <MESSAGE>"
.
You'll need to implement functions that correspond with log levels.
For example, the below snippet demonstrates an expected output for the log
function.
log(LogLevel::Error, "Stack overflow")
// Returns: "[ERROR]: Stack overflow"
And for info
:
info("Timezone changed")
// Returns: "[INFO]: Timezone changed"
Have fun!
Sign up to Exercism to learn and master Cairo with 66 exercises, and real human mentoring, all for free.