Skip to content

Commit

Permalink
feat: vector of enum
Browse files Browse the repository at this point in the history
Signed-off-by: Fredrik Klingenberg <fredrkl@gmail.com>
  • Loading branch information
fredrkl committed Nov 19, 2023
1 parent a67fcb1 commit 5b34b3f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion projects/collections/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
}
}

}

0 comments on commit 5b34b3f

Please sign in to comment.