| 85 | } |
| 86 | |
| 87 | pub fn parse_shadow_content(content: impl BufRead) -> Result<Vec<ShadowEntry>> { |
| 88 | let mut entries = vec![]; |
| 89 | for (line_num, line) in content.lines().enumerate() { |
| 90 | let input = |
| 91 | line.with_context(|| format!("failed to read shadow entry at line {line_num}"))?; |
| 92 | |
| 93 | // Skip empty and comment lines |
| 94 | if input.is_empty() || input.starts_with('#') { |
| 95 | continue; |
| 96 | } |
| 97 | |
| 98 | let entry = ShadowEntry::parse_line(&input).ok_or_else(|| { |
| 99 | anyhow!( |
| 100 | "failed to parse shadow entry at line {}, content: {}", |
| 101 | line_num, |
| 102 | &input |
| 103 | ) |
| 104 | })?; |
| 105 | entries.push(entry); |
| 106 | } |
| 107 | Ok(entries) |
| 108 | } |
| 109 | |
| 110 | #[cfg(test)] |
| 111 | mod tests { |