Skip to content

Commit

Permalink
Parse parameters from reader instead of string and get_id()
Browse files Browse the repository at this point in the history
  • Loading branch information
confunguido committed Oct 10, 2024
1 parent e263c03 commit 90c9a27
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ rand = "0.8.5"
csv = "1.3"
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0"
toml = "0.8.19"
serde_json = "1.0.128"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/parameter-loading/incidence_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn handle_infection_status_change(
) {
context.send_report(IncidenceReportItem {
time: context.get_current_time(),
person_id: event.person_id.id,
person_id: event.person_id.get_id(),
infection_status: event.current,
});
}
Expand Down
6 changes: 4 additions & 2 deletions src/global_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::collections::HashMap;
use std::fmt::{self, Debug, Display};
use std::fs;
use std::io;
use std::io::BufReader;
use std::path::Path;

/// Defines a global property with the following parameters:
Expand Down Expand Up @@ -136,8 +137,9 @@ impl ContextGlobalPropertiesExt for Context {
&mut self,
file_name: &Path,
) -> Result<T, IxaError> {
let config_file = fs::read_to_string(file_name)?;
let config = serde_json::from_str(&config_file)?;
let config_file = fs::File::open(file_name)?;
let reader = BufReader::new(config_file);
let config = serde_json::from_reader(reader)?;
Ok(config)
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/people.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ define_data_plugin!(
// 0 to population - 1 in the PeopleData container.
#[derive(Clone, Copy, Hash, PartialEq, Eq, Serialize, Deserialize)]
pub struct PersonId {
pub id: usize,
id: usize,
}

impl fmt::Debug for PersonId {
Expand All @@ -37,6 +37,12 @@ impl fmt::Debug for PersonId {
}
}

impl PersonId {
#[must_use]
pub fn get_id(&self) -> usize {
self.id
}
}
// Individual characteristics or states related to a person, such as age or
// disease status, are represented as "person properties". These properties
// * are represented by a struct type that implements the PersonProperty trait,
Expand Down

0 comments on commit 90c9a27

Please sign in to comment.