-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "challenge" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Defining a simple enum | ||
enum Weekday { | ||
Monday, | ||
Tuesday, | ||
Wednesday, | ||
Thursday, | ||
Friday, | ||
} | ||
|
||
// Enum with associated values | ||
enum Status { | ||
Success(u32), | ||
Error(String), | ||
} | ||
|
||
fn main() { | ||
// Using enums in Rust | ||
let today = Weekday::Wednesday; | ||
let result = Status::Success(42); | ||
|
||
// Pattern matching on enums | ||
match today { | ||
Weekday::Friday => println!("It's Friday! 🎉"), | ||
_ => println!("It's not Friday yet. Keep coding! 💻"), | ||
} | ||
|
||
// Handling different cases of the Status enum | ||
match result { | ||
Status::Success(value) => println!("Operation was successful with value: {}", value), | ||
Status::Error(message) => println!("An error occurred: {}", message), | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("30 days rust!"); | ||
} |