fn write_lines()

in src/cobertura.rs [504:563]


fn write_lines(writer: &mut Writer<Cursor<Vec<u8>>>, lines: &[Line]) {
    let lines_tag = "lines";
    let line_tag = "line";

    writer
        .write_event(Event::Start(BytesStart::from_content(
            lines_tag,
            lines_tag.len(),
        )))
        .unwrap();
    for line in lines {
        let mut l = BytesStart::from_content(line_tag, line_tag.len());
        match line {
            Line::Plain {
                ref number,
                ref hits,
            } => {
                l.push_attribute(("number", number.to_string().as_ref()));
                l.push_attribute(("hits", hits.to_string().as_ref()));
                writer.write_event(Event::Empty(l)).unwrap();
            }
            Line::Branch {
                ref number,
                ref hits,
                conditions,
            } => {
                l.push_attribute(("number", number.to_string().as_ref()));
                l.push_attribute(("hits", hits.to_string().as_ref()));
                l.push_attribute(("branch", "true"));
                writer.write_event(Event::Start(l)).unwrap();

                let conditions_tag = "conditions";
                let condition_tag = "condition";

                writer
                    .write_event(Event::Start(BytesStart::from_content(
                        conditions_tag,
                        conditions_tag.len(),
                    )))
                    .unwrap();
                for condition in conditions {
                    let mut c = BytesStart::from_content(condition_tag, condition_tag.len());
                    c.push_attribute(("number", condition.number.to_string().as_ref()));
                    c.push_attribute(("type", condition.cond_type.to_string().as_ref()));
                    c.push_attribute(("coverage", condition.coverage.to_string().as_ref()));
                    writer.write_event(Event::Empty(c)).unwrap();
                }
                writer
                    .write_event(Event::End(BytesEnd::new(conditions_tag)))
                    .unwrap();
                writer
                    .write_event(Event::End(BytesEnd::new(line_tag)))
                    .unwrap();
            }
        }
    }
    writer
        .write_event(Event::End(BytesEnd::new(lines_tag)))
        .unwrap();
}