From f9db002464174a07b143fc58e2cca35081518209 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Wed, 6 Dec 2023 23:32:33 -0500 Subject: [PATCH] Make the series open function accept anything that can be a path reference --- emseries/src/series.rs | 2 +- emseries/tests/test_io.rs | 52 +++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/emseries/src/series.rs b/emseries/src/series.rs index 71e089f..98f0cb1 100644 --- a/emseries/src/series.rs +++ b/emseries/src/series.rs @@ -42,7 +42,7 @@ where { /// Open a time series database at the specified path. `path` is the full path and filename for /// the database. - pub fn open(path: &str) -> Result, EmseriesReadError> { + pub fn open>(path: P) -> Result, EmseriesReadError> { let f = OpenOptions::new() .read(true) .append(true) diff --git a/emseries/tests/test_io.rs b/emseries/tests/test_io.rs index c599369..3f26f16 100644 --- a/emseries/tests/test_io.rs +++ b/emseries/tests/test_io.rs @@ -99,8 +99,8 @@ mod test { { let tmp_file = tempfile::NamedTempFile::new().expect("temporary path created"); let tmp_path = tmp_file.into_temp_path(); - let ts: Series = Series::open(&tmp_path.to_string_lossy()) - .expect("the time series should open correctly"); + let ts: Series = + Series::open(&tmp_path).expect("the time series should open correctly"); test(ts); } @@ -136,8 +136,8 @@ mod test { pub fn can_search_for_an_entry_with_exact_time() { run_test(|path| { let trips = mk_trips(); - let mut ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let mut ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); for trip in &trips[0..=4] { ts.put(trip.clone()).expect("expect a successful put"); @@ -157,8 +157,8 @@ mod test { pub fn can_get_entries_in_time_range() { run_test(|path| { let trips = mk_trips(); - let mut ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let mut ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); for trip in &trips[0..=4] { ts.put(trip.clone()).expect("expect a successful put"); @@ -186,8 +186,8 @@ mod test { let trips = mk_trips(); { - let mut ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let mut ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); for trip in &trips[0..=4] { ts.put(trip.clone()).expect("expect a successful put"); @@ -195,8 +195,8 @@ mod test { } { - let ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); let v: Vec<(&UniqueId, &BikeTrip)> = ts.search_sorted( time_range( DateTimeTz(UTC.with_ymd_and_hms(2011, 10, 31, 0, 0, 0).unwrap()).into(), @@ -220,8 +220,8 @@ mod test { let trips = mk_trips(); { - let mut ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let mut ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); for trip in &trips[0..=2] { ts.put(trip.clone()).expect("expect a successful put"); @@ -229,8 +229,8 @@ mod test { } { - let mut ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let mut ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); let v: Vec<(&UniqueId, &BikeTrip)> = ts.search_sorted( time_range( DateTimeTz(UTC.with_ymd_and_hms(2011, 10, 31, 0, 0, 0).unwrap()).into(), @@ -248,8 +248,8 @@ mod test { } { - let ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); let v: Vec<(&UniqueId, &BikeTrip)> = ts.search_sorted( time_range( DateTimeTz(UTC.with_ymd_and_hms(2011, 10, 31, 0, 0, 0).unwrap()).into(), @@ -273,8 +273,8 @@ mod test { run_test(|path| { let trips = mk_trips(); - let mut ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let mut ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); ts.put(trips[0].clone()).expect("expect a successful put"); ts.put(trips[1].clone()).expect("expect a successful put"); @@ -310,8 +310,8 @@ mod test { let trips = mk_trips(); { - let mut ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let mut ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); ts.put(trips[0].clone()).expect("expect a successful put"); ts.put(trips[1].clone()).expect("expect a successful put"); @@ -327,8 +327,8 @@ mod test { } { - let ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); let trips: Vec<(&UniqueId, &BikeTrip)> = ts.records().collect(); assert_eq!(trips.len(), 3); @@ -356,8 +356,8 @@ mod test { let trips = mk_trips(); { - let mut ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let mut ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); let trip_id = ts.put(trips[0].clone()).expect("expect a successful put"); ts.put(trips[1].clone()).expect("expect a successful put"); ts.put(trips[2].clone()).expect("expect a successful put"); @@ -368,8 +368,8 @@ mod test { } { - let ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); let recs: Vec<(&UniqueId, &BikeTrip)> = ts.records().collect(); assert_eq!(recs.len(), 2); }