diff --git a/src/view/layout.rs b/src/view/layout.rs index ce26fd6..2d5b7b5 100644 --- a/src/view/layout.rs +++ b/src/view/layout.rs @@ -1,3 +1,5 @@ +use std::rc::Rc; + use crate::model::cell::{CellKey, CellValue}; use crate::model::Model; use crate::view::{Axis, View}; @@ -38,8 +40,8 @@ pub struct GridLayout { /// Categories on `Axis::None` — hidden, implicitly aggregated. pub none_cats: Vec, /// In records mode: the filtered cell list, one per row. - /// None for normal pivot views. - pub records: Option>, + /// None for normal pivot views. Rc for cheap sharing. + pub records: Option>>, } impl GridLayout { @@ -48,12 +50,11 @@ impl GridLayout { pub fn with_frozen_records( model: &Model, view: &View, - frozen_records: Option>, + frozen_records: Option>>, ) -> Self { let mut layout = Self::new(model, view); if layout.is_records_mode() { if let Some(records) = frozen_records { - // Re-build with the frozen records instead let row_items: Vec = (0..records.len()) .map(|i| AxisEntry::DataItem(vec![i.to_string()])) .collect(); @@ -183,7 +184,7 @@ impl GridLayout { row_items, col_items, none_cats, - records: Some(records), + records: Some(Rc::new(records)), } } @@ -301,7 +302,7 @@ impl GridLayout { .map(|i| AxisEntry::DataItem(vec![i.to_string()])) .collect(); self.row_items = new_row_items; - self.records = Some(new_records); + self.records = Some(Rc::new(new_records)); } }