diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..13df4d9 --- /dev/null +++ b/Cargo.toml @@ -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] diff --git a/src/enum.rs b/src/enum.rs new file mode 100644 index 0000000..7829d57 --- /dev/null +++ b/src/enum.rs @@ -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), + } +} diff --git a/hello_world.rs b/src/hello_world.rs similarity index 100% rename from hello_world.rs rename to src/hello_world.rs diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..1682dc9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("30 days rust!"); +}