use std::iter::FromIterator; use crate::{ grid::dimension::CompleteDimensionVecRecords, grid::records::Records, settings::TableOption, }; /// A structure used to set [`Table`] width via a list of columns widths. /// /// [`Table`]: crate::Table #[derive(Debug)] pub struct WidthList { list: Vec, } impl WidthList { /// Creates a new object. pub fn new(list: Vec) -> Self { Self { list } } } impl From> for WidthList { fn from(list: Vec) -> Self { Self::new(list) } } impl FromIterator for WidthList { fn from_iter>(iter: T) -> Self { Self::new(iter.into_iter().collect()) } } impl TableOption, C> for WidthList where R: Records, { fn change( self, records: &mut R, _: &mut C, dimension: &mut CompleteDimensionVecRecords<'static>, ) { if self.list.len() < records.count_columns() { return; } let _ = dimension.set_widths(self.list); } }