enum Mark { Circle { r: f64 }, Rect { w: f64, h: f64 }, Label { text: Vec }, Dot, } fn main() { use std::io::{self, Write}; let mut marks: Vec = Vec::new(); let mut mark_at: Vec = Vec::new(); for mark in [Mark::Label { text: b"hello, goose".to_vec() }, Mark::Circle { r: 1.5 }, Mark::Dot, Mark::Rect { w: 2.0, h: 3.0 }, Mark::Label { text: b"x".to_vec() }] { mark_at.push(marks.len()); marks.push(mark); } let mut out=io::stdout().lock(); for i in [3, 0, 4, 1, 2] { match &marks[mark_at[i]] { Mark::Circle { r } => writeln!(&mut out,"{i}: circle {r}").unwrap(), Mark::Rect { w, h } => writeln!(&mut out,"{i}: rect {w} by {h}").unwrap(), Mark::Label { text } => { write!(&mut out,"{i}: label \"").unwrap(); out.write_all(text).unwrap(); writeln!(&mut out,"\"").unwrap(); } Mark::Dot => writeln!(&mut out,"{i}: dot").unwrap(), } } }