Skip to content

Commit

Permalink
use vector of strings for locators
Browse files Browse the repository at this point in the history
  • Loading branch information
bryevdv committed Oct 23, 2023
1 parent 7182c1a commit 12fb3ed
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 22 deletions.
21 changes: 13 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2539,18 +2539,23 @@ impl UiExtra for egui::Ui {
}

#[cfg(not(target_arch = "wasm32"))]
pub fn start(mut data_sources: Vec<Box<dyn DeferredDataSource>>) {
pub fn start(data_sources: Vec<Box<dyn DeferredDataSource>>) {
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,
Expand Down
6 changes: 3 additions & 3 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub struct SlotMetaTile {

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct DataSourceDescription {
pub source_locator: Option<String>,
pub source_locator: Vec<String>,
}

pub trait DataSource {
Expand All @@ -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,
Expand All @@ -239,7 +239,7 @@ pub trait DataSourceMut {
}

impl<T: DataSource> DataSourceMut for T {
fn fetch_description(&mut self) -> DataSourceDescription {
fn fetch_description(&self) -> DataSourceDescription {
DataSource::fetch_description(self)
}
fn fetch_info(&mut self) -> DataSourceInfo {
Expand Down
10 changes: 5 additions & 5 deletions src/deferred_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataSourceInfo>;
fn fetch_summary_tile(&mut self, entry_id: &EntryID, tile_id: TileID, full: bool);
Expand Down Expand Up @@ -36,7 +36,7 @@ impl<T: DataSourceMut> DeferredDataSourceWrapper<T> {
}

impl<T: DataSourceMut> DeferredDataSource for DeferredDataSourceWrapper<T> {
fn fetch_description(&mut self) -> DataSourceDescription {
fn fetch_description(&self) -> DataSourceDescription {
self.data_source.fetch_description()
}

Expand Down Expand Up @@ -108,7 +108,7 @@ impl<T: DeferredDataSource> CountingDeferredDataSource<T> {
}

impl<T: DeferredDataSource> DeferredDataSource for CountingDeferredDataSource<T> {
fn fetch_description(&mut self) -> DataSourceDescription {
fn fetch_description(&self) -> DataSourceDescription {
self.data_source.fetch_description()
}

Expand Down Expand Up @@ -155,8 +155,8 @@ impl<T: DeferredDataSource> DeferredDataSource for CountingDeferredDataSource<T>
}

impl DeferredDataSource for Box<dyn DeferredDataSource> {
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) {
Expand Down
2 changes: 1 addition & 1 deletion src/file_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()],
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/parallel_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<T: DataSource + Send + Sync + 'static> ParallelDeferredDataSource<T> {
}

impl<T: DataSource + Send + Sync + 'static> DeferredDataSource for ParallelDeferredDataSource<T> {
fn fetch_description(&mut self) -> DataSourceDescription {
fn fetch_description(&self) -> DataSourceDescription {
self.data_source.fetch_description()
}

Expand Down

0 comments on commit 12fb3ed

Please sign in to comment.