From 8c987bc5008a26de781fd3d865bbf3fd952b4d56 Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Tue, 27 Aug 2024 16:01:36 -0700 Subject: [PATCH 1/2] StripDataSource. --- src/lib.rs | 1 + src/strip_data.rs | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/strip_data.rs diff --git a/src/lib.rs b/src/lib.rs index 753c67b..39aa2b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,4 +11,5 @@ pub mod http; pub mod merge_data; #[cfg(not(target_arch = "wasm32"))] pub mod parallel_data; +pub mod strip_data; pub mod timestamp; diff --git a/src/strip_data.rs b/src/strip_data.rs new file mode 100644 index 0000000..87f4677 --- /dev/null +++ b/src/strip_data.rs @@ -0,0 +1,57 @@ +use crate::data::{ + DataSourceDescription, DataSourceInfo, EntryID, EntryIndex, EntryInfo, Field, ItemLink, + ItemUID, SlotMetaTile, SlotTile, SummaryTile, TileID, DataSource, +}; + +pub struct StripDataSource { + data_source: T, +} + + +impl StripDataSource { + pub fn new(data_source: T) -> Self { + Self { + data_source, + } + } +} + +impl DataSource for StripDataSource { + fn fetch_description(&self) -> DataSourceDescription { + self.data_source.fetch_description() + } + + fn fetch_info(&self) -> DataSourceInfo { + self.data_source.fetch_info() + } + + fn fetch_summary_tile(&self, entry_id: &EntryID, tile_id: TileID, full: bool) -> SummaryTile { + self.data_source.fetch_summary_tile(entry_id, tile_id, full) + } + + fn fetch_slot_tile(&self, entry_id: &EntryID, tile_id: TileID, full: bool) -> SlotTile { + self.data_source.fetch_slot_tile(entry_id, tile_id, full) + } + + fn fetch_slot_meta_tile(&self, entry_id: &EntryID, tile_id: TileID, full: bool) -> SlotMetaTile { + let mut tile = self.data_source + .fetch_slot_meta_tile(entry_id, tile_id, full); + for row in &mut tile.data.items { + for item in row { + item.title = "Redacted".to_string(); + for field in item.fields { + match field.1 { + Field::I64(_) => {}, + Field::U64(_) => {}, + Field::String(x) => { *x = "Redacted".to_string(); }, + Field::Interval(_) => {}, + Field::ItemLink(ItemLink { title, .. }) => { *title = "Redacted".to_string(); }, + Field::Vec(_) => { todo!() }, + Field::Empty => {}, + } + } + } + } + tile + } +} From 19facae30d5373206042e230a7bdbac623e1a8f7 Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Tue, 27 Aug 2024 16:04:14 -0700 Subject: [PATCH 2/2] Fix the build. --- src/strip_data.rs | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/strip_data.rs b/src/strip_data.rs index 87f4677..965f33c 100644 --- a/src/strip_data.rs +++ b/src/strip_data.rs @@ -1,18 +1,15 @@ use crate::data::{ - DataSourceDescription, DataSourceInfo, EntryID, EntryIndex, EntryInfo, Field, ItemLink, - ItemUID, SlotMetaTile, SlotTile, SummaryTile, TileID, DataSource, + DataSource, DataSourceDescription, DataSourceInfo, EntryID, Field, ItemLink, SlotMetaTile, + SlotTile, SummaryTile, TileID, }; pub struct StripDataSource { data_source: T, } - impl StripDataSource { pub fn new(data_source: T) -> Self { - Self { - data_source, - } + Self { data_source } } } @@ -33,21 +30,33 @@ impl DataSource for StripDataSource { self.data_source.fetch_slot_tile(entry_id, tile_id, full) } - fn fetch_slot_meta_tile(&self, entry_id: &EntryID, tile_id: TileID, full: bool) -> SlotMetaTile { - let mut tile = self.data_source + fn fetch_slot_meta_tile( + &self, + entry_id: &EntryID, + tile_id: TileID, + full: bool, + ) -> SlotMetaTile { + let mut tile = self + .data_source .fetch_slot_meta_tile(entry_id, tile_id, full); for row in &mut tile.data.items { for item in row { item.title = "Redacted".to_string(); - for field in item.fields { + for field in &mut item.fields { match field.1 { - Field::I64(_) => {}, - Field::U64(_) => {}, - Field::String(x) => { *x = "Redacted".to_string(); }, - Field::Interval(_) => {}, - Field::ItemLink(ItemLink { title, .. }) => { *title = "Redacted".to_string(); }, - Field::Vec(_) => { todo!() }, - Field::Empty => {}, + Field::I64(_) => {} + Field::U64(_) => {} + Field::String(ref mut x) => { + *x = "Redacted".to_string(); + } + Field::Interval(_) => {} + Field::ItemLink(ItemLink { ref mut title, .. }) => { + *title = "Redacted".to_string(); + } + Field::Vec(_) => { + todo!() + } + Field::Empty => {} } } }