From d7d02a493553eaa03fddb8a08b546ab3326548e3 Mon Sep 17 00:00:00 2001 From: Sil Klaasboer Date: Thu, 18 Dec 2025 14:08:01 +0100 Subject: [PATCH] add enums and data holding enums --- containers/Cargo.lock | 7 +++++++ containers/Cargo.toml | 6 ++++++ containers/src/main.rs | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 containers/Cargo.lock create mode 100644 containers/Cargo.toml create mode 100644 containers/src/main.rs diff --git a/containers/Cargo.lock b/containers/Cargo.lock new file mode 100644 index 0000000..ea82ab9 --- /dev/null +++ b/containers/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "containers" +version = "0.1.0" diff --git a/containers/Cargo.toml b/containers/Cargo.toml new file mode 100644 index 0000000..a1b03d6 --- /dev/null +++ b/containers/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "containers" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/containers/src/main.rs b/containers/src/main.rs new file mode 100644 index 0000000..7661ff4 --- /dev/null +++ b/containers/src/main.rs @@ -0,0 +1,32 @@ +enum Direction +{ + Up, + Down, + Left, + Right +} + +enum Status +{ + Succeeded(String), + Failed(String) +} + +fn main() { + // normal Enum + let direction = Direction::Down; + match direction { + Direction::Up => println!("Going up"), + Direction::Down => println!("Going down"), + Direction::Left => println!("Going left"), + Direction::Right => println!("Going right"), + } + + // enum holding data + let status = Status::Failed(String::from("Authentication Failed")); + match status + { + Status::Succeeded(message) => println!("Succeeded with msg: {}",message), + Status::Failed(message) => println!("Failed with msg: {}",message), + } +}