// Iterators of Code 2026 — Day 07: Read the envelope // Refactor headers using iterators. Collect lines before the first empty line, // excluding the separator. Nonempty lines after the separator are body text. // A whitespace-only line is NOT empty for this simplified message format. fn headers<'a>(lines: &[&'a str]) -> Vec<&'a str> { let mut result = Vec::new(); for &line in lines { if line.is_empty() { break; } result.push(line); } result } fn main() { assert_eq!( headers(&["From: Ada", "Subject: Lunch", "", "Bring a sandwich"]), ["From: Ada", "Subject: Lunch"] ); assert_eq!(headers(&["From: Ada", " "]), ["From: Ada", " "]); assert!(headers(&["", "Body only"]).is_empty()); assert!(headers(&[]).is_empty()); }