1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use super::{Cell, RowStyle};
use std::iter::{FromIterator, IntoIterator};

#[derive(Debug, Clone)]
pub struct Row {
    pub cells: Vec<Cell>,
    pub style: crate::RowStyle,
}

impl Row {
    pub fn new(cells: impl IntoIterator<Item = Cell>) -> Self {
        Self {
            cells: cells.into_iter().collect(),
            style: Default::default(),
        }
    }

    pub fn with_style(mut self, style: RowStyle) -> Self {
        self.style = style;
        self
    }

    pub fn weight_sum(&self) -> f64 {
        self.cells.iter().map(|c| c.weight).sum()
    }
}

impl FromIterator<Cell> for Row {
    fn from_iter<I: IntoIterator<Item = Cell>>(iter: I) -> Self {
        Self::new(iter)
    }
}