From 5b34b3f6c73445940bf46e70ce6f90bfb11a4fd7 Mon Sep 17 00:00:00 2001 From: Fredrik Klingenberg Date: Sun, 19 Nov 2023 11:52:23 +0100 Subject: [PATCH] feat: vector of enum Signed-off-by: Fredrik Klingenberg --- projects/collections/src/main.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/projects/collections/src/main.rs b/projects/collections/src/main.rs index 0db21b0..61aec9e 100644 --- a/projects/collections/src/main.rs +++ b/projects/collections/src/main.rs @@ -31,6 +31,22 @@ fn main() { } for i in &v { - println!("{i}") + println!("{i}"); + } + + enum SpreadsheetCell { + Int(i32), + Float(f64), + Text(String), } + + let row = vec![SpreadsheetCell::Int(3), SpreadsheetCell::Text(String::from("blue")), SpreadsheetCell::Float(10.12)]; + for i in &row { + match i { + SpreadsheetCell::Text(i) => println!("{i}"), + SpreadsheetCell::Float(i) => println!("{i}"), + SpreadsheetCell::Int(i) => println!("{i}") + } + } + }