
📎 This article includes 1 downloadable practice file ↓
“`rust
struct Line { item: String, qty: u32, rate: f64 }
impl Line { fn amount(&self) -> f64 { self.qty as f64 * self.rate } }
enum Status { Paid, Pending { days: u32 }, Cancelled }
fn label(s: &Status) -> String {
match s {
Status::Paid => “Paid”.into(),
Status::Pending { days } => format!(“Pending {days} days”),
Status::Cancelled => “Cancelled”.into(),
}
}
“`
match must cover every variant, so adding a new status forces you to handle it everywhere. The project file uses an enum for row errors.
Code for this course follows standard, current syntax; we test JavaScript and PowerShell scripts before publishing, and R/Java/Rust examples are kept to core language features. Tell us if anything fails on your setup.
Practice
Add the Line struct and Status enum to a project and print labels.
📎 Practice files for this article
- 📄rust-csv-summary-main.rsLesson code file.⬇ RS · 1 KB
Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.
Stuck on a step? Ask a question and the AI answers using this article.