From 12fb3ed00f705a7fbfd05b6417e29678ce5b6264 Mon Sep 17 00:00:00 2001 From: Bryan Van de Ven Date: Mon, 23 Oct 2023 11:09:36 -0700 Subject: [PATCH] use vector of strings for locators --- src/app.rs | 21 +++++++++++++-------- src/data.rs | 6 +++--- src/deferred_data.rs | 10 +++++----- src/file_data.rs | 2 +- src/http/client.rs | 4 ++-- src/main.rs | 4 ++-- src/parallel_data.rs | 2 +- 7 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/app.rs b/src/app.rs index bc49a39..b25c997 100644 --- a/src/app.rs +++ b/src/app.rs @@ -2539,18 +2539,23 @@ impl UiExtra for egui::Ui { } #[cfg(not(target_arch = "wasm32"))] -pub fn start(mut data_sources: Vec>) { +pub fn start(data_sources: Vec>) { env_logger::try_init().unwrap_or(()); // Log to stderr (if you run with `RUST_LOG=debug`). - let app_name = if data_sources.len() == 1 { - match data_sources[0].fetch_description().source_locator { - Some(source_locator) => format!("{source_locator} - Legion Prof"), - _ => "Unknown Data Source - Legion Prof".to_string(), - } - } else { - "Unknown Data Source - Legion Prof".to_string() + let all_locators = data_sources.iter().fold(Vec::new(), |acc, x| { + acc.into_iter() + .chain(x.fetch_description().source_locator) + .collect() + }); + + let locator = match &all_locators[..] { + [] => "No data source".to_string(), + [x] => x.to_string(), + [x, ..] => format!("{} and {} other sources", x, all_locators.len() - 1), }; + let app_name = format!("{locator} - Legion Prof"); + let native_options = eframe::NativeOptions::default(); eframe::run_native( &app_name, diff --git a/src/data.rs b/src/data.rs index 2c152fb..a4fc1e7 100644 --- a/src/data.rs +++ b/src/data.rs @@ -208,7 +208,7 @@ pub struct SlotMetaTile { #[derive(Debug, Clone, Deserialize, Serialize)] pub struct DataSourceDescription { - pub source_locator: Option, + pub source_locator: Vec, } pub trait DataSource { @@ -221,7 +221,7 @@ pub trait DataSource { } pub trait DataSourceMut { - fn fetch_description(&mut self) -> DataSourceDescription; + fn fetch_description(&self) -> DataSourceDescription; fn fetch_info(&mut self) -> DataSourceInfo; fn fetch_summary_tile( &mut self, @@ -239,7 +239,7 @@ pub trait DataSourceMut { } impl DataSourceMut for T { - fn fetch_description(&mut self) -> DataSourceDescription { + fn fetch_description(&self) -> DataSourceDescription { DataSource::fetch_description(self) } fn fetch_info(&mut self) -> DataSourceInfo { diff --git a/src/deferred_data.rs b/src/deferred_data.rs index b58f113..d2fa083 100644 --- a/src/deferred_data.rs +++ b/src/deferred_data.rs @@ -4,7 +4,7 @@ use crate::data::{ }; pub trait DeferredDataSource { - fn fetch_description(&mut self) -> DataSourceDescription; + fn fetch_description(&self) -> DataSourceDescription; fn fetch_info(&mut self); fn get_infos(&mut self) -> Vec; fn fetch_summary_tile(&mut self, entry_id: &EntryID, tile_id: TileID, full: bool); @@ -36,7 +36,7 @@ impl DeferredDataSourceWrapper { } impl DeferredDataSource for DeferredDataSourceWrapper { - fn fetch_description(&mut self) -> DataSourceDescription { + fn fetch_description(&self) -> DataSourceDescription { self.data_source.fetch_description() } @@ -108,7 +108,7 @@ impl CountingDeferredDataSource { } impl DeferredDataSource for CountingDeferredDataSource { - fn fetch_description(&mut self) -> DataSourceDescription { + fn fetch_description(&self) -> DataSourceDescription { self.data_source.fetch_description() } @@ -155,8 +155,8 @@ impl DeferredDataSource for CountingDeferredDataSource } impl DeferredDataSource for Box { - fn fetch_description(&mut self) -> DataSourceDescription { - self.as_mut().fetch_description() + fn fetch_description(&self) -> DataSourceDescription { + self.as_ref().fetch_description() } fn fetch_info(&mut self) { diff --git a/src/file_data.rs b/src/file_data.rs index 6202936..2df2e4c 100644 --- a/src/file_data.rs +++ b/src/file_data.rs @@ -33,7 +33,7 @@ impl FileDataSource { impl DataSource for FileDataSource { fn fetch_description(&self) -> DataSourceDescription { DataSourceDescription { - source_locator: Some(String::from(self.basedir.to_string_lossy())), + source_locator: vec![String::from(self.basedir.to_string_lossy())], } } fn fetch_info(&self) -> DataSourceInfo { diff --git a/src/http/client.rs b/src/http/client.rs index 2095eaf..7f6c59f 100644 --- a/src/http/client.rs +++ b/src/http/client.rs @@ -64,9 +64,9 @@ impl HTTPClientDataSource { } impl DeferredDataSource for HTTPClientDataSource { - fn fetch_description(&mut self) -> DataSourceDescription { + fn fetch_description(&self) -> DataSourceDescription { DataSourceDescription { - source_locator: Some(self.baseurl.to_string()), + source_locator: vec![self.baseurl.to_string()], } } diff --git a/src/main.rs b/src/main.rs index 8e69e80..af0843d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -268,9 +268,9 @@ impl RandomDataSource { } impl DataSourceMut for RandomDataSource { - fn fetch_description(&mut self) -> DataSourceDescription { + fn fetch_description(&self) -> DataSourceDescription { DataSourceDescription { - source_locator: Some(String::from("Random Data Source")), + source_locator: vec![String::from("Random Data Source")], } } fn fetch_info(&mut self) -> DataSourceInfo { diff --git a/src/parallel_data.rs b/src/parallel_data.rs index e61f623..870bce9 100644 --- a/src/parallel_data.rs +++ b/src/parallel_data.rs @@ -27,7 +27,7 @@ impl ParallelDeferredDataSource { } impl DeferredDataSource for ParallelDeferredDataSource { - fn fetch_description(&mut self) -> DataSourceDescription { + fn fetch_description(&self) -> DataSourceDescription { self.data_source.fetch_description() }