5/5
# Enum ## Example Execute the following command to run [`./solutions/examples/enum.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/enum_type/solutions/examples/enum.rs) ```shell cargo run --example enum ``` ## Exercises Exercises are in [`./exercises/src/lib.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/enum_type/exercises/src/lib.rs) ### Exercise 1 ```rust #[derive(Debug, PartialEq)] pub enum Color {} ``` Create an `enum` named `Color` having the values - `Red` - `Green` - `Blue` - `Rgba(u8, u8, u8, f32)` Prefix the `enum` with the keyword `pub`. This will make the `enum` public so that it can be imported into other rust files, including the test file. ## Test ```shell cargo test ```
Execute the following command to run ./solutions/examples/enum.rs
Exercises are in ./exercises/src/lib.rs
Create an enum
named Color
having the values
Red
Green
Blue
Rgba(u8, u8, u8, f32)
Prefix the enum
with the keyword pub
. This will make the enum
public so that it can be imported into other rust files, including the test file.
A practical introduction to Rust Enums - Define your own custom types by creating a `Color` enum with variants such as `Red`, `Green`, and `Blue`. Learn to include variants that hold data, like `Rgba(u8, u8, u8, f32)`, and make your enums public for broader use.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Introduction to the Rust programming language
Rust variables and functions
Scalar types, arrays, strings, enum, structs, vectors, and hash maps in Rust
Rust control flows: If / else, if let and let else, loop, match
Rust ownership, including borrow and references
Rust error handling
Rust Modules
Rust Traits
Last updated on July 11, 2025
Rust Developer
Rust Programming BasicsDuration: 6min
Duration: 18min
Duration: 47min
Duration: 15min
Duration: 19min
Duration: 8min
Duration: 12min
Duration: 46min
Duration: 14min
Course Overview
About the course
Introduction to the Rust programming language
Rust variables and functions
Scalar types, arrays, strings, enum, structs, vectors, and hash maps in Rust
Rust control flows: If / else, if let and let else, loop, match
Rust ownership, including borrow and references
Rust error handling
Rust Modules
Rust Traits
Last updated on July 11, 2025