Skip to content

Commit 5d6a289

Browse files
authored
Fix issues with Time, Positin, Location newtypes (#212)
* Add Time, Position, Location to prelude. * Closes #209 * Fix Display for f64-based newtypes * Add tests of Time/Position/Location Display * Closes #208
1 parent 99930e8 commit 5d6a289

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/_macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ macro_rules! impl_f64_newtypes {
368368
($type: ty) => {
369369
impl std::fmt::Display for $type {
370370
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
371-
write!(f, "{}({})", stringify!($idtype), self.0)
371+
write!(f, "{}({})", stringify!($type), self.0)
372372
}
373373
}
374374

src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,33 @@ pub fn c_api_version() -> String {
486486
#[cfg(test)]
487487
mod tests {
488488
use super::c_api_version;
489+
use super::Location;
490+
use super::Position;
491+
use super::Time;
489492

490493
#[test]
491494
fn test_c_api_version() {
492495
let _ = c_api_version();
493496
}
497+
498+
#[test]
499+
fn test_f64_newtype_Display() {
500+
let x = Position::from(1.0);
501+
let mut output = String::new();
502+
std::fmt::write(&mut output, format_args!("{}", x))
503+
.expect("Error occurred while trying to write in String");
504+
assert_eq!(output, "Position(1)".to_string());
505+
let x = Time::from(1.0);
506+
let mut output = String::new();
507+
std::fmt::write(&mut output, format_args!("{}", x))
508+
.expect("Error occurred while trying to write in String");
509+
assert_eq!(output, "Time(1)".to_string());
510+
let x = Location::from(1.0);
511+
let mut output = String::new();
512+
std::fmt::write(&mut output, format_args!("{}", x))
513+
.expect("Error occurred while trying to write in String");
514+
assert_eq!(output, "Location(1)".to_string());
515+
}
494516
}
495517

496518
// Testing modules

src/prelude.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub use crate::TSK_NODE_IS_SAMPLE;
88
pub use streaming_iterator::DoubleEndedStreamingIterator;
99
pub use streaming_iterator::StreamingIterator;
1010
pub use {
11-
crate::EdgeId, crate::IndividualId, crate::MigrationId, crate::MutationId, crate::NodeId,
12-
crate::PopulationId, crate::SiteId, crate::SizeType,
11+
crate::EdgeId, crate::IndividualId, crate::Location, crate::MigrationId, crate::MutationId,
12+
crate::NodeId, crate::PopulationId, crate::Position, crate::SiteId, crate::SizeType,
13+
crate::Time,
1314
};

0 commit comments

Comments
 (0)