Skip to content

Commit 985997a

Browse files
committed
feat: make load from file generic over AsRef<str>
* for TableCollection * for TreeSequence
1 parent cf545e0 commit 985997a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/table_collection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@ impl TableCollection {
138138
///
139139
/// This function allocates a `CString` to pass the file name to the C API.
140140
/// A panic will occur if the system runs out of memory.
141-
pub fn new_from_file(filename: &str) -> Result<Self, TskitError> {
141+
pub fn new_from_file(filename: impl AsRef<str>) -> Result<Self, TskitError> {
142142
// Arbitrary sequence_length.
143143
let mut tables = match TableCollection::new(1.0) {
144144
Ok(t) => (t),
145145
Err(e) => return Err(e),
146146
};
147147

148-
let c_str = std::ffi::CString::new(filename).unwrap();
148+
let c_str = std::ffi::CString::new(filename.as_ref()).unwrap();
149149
let rv = unsafe {
150150
ll_bindings::tsk_table_collection_load(
151151
tables.as_mut_ptr(),

src/trees.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,8 +1042,8 @@ impl TreeSequence {
10421042
}
10431043

10441044
/// Load from a file.
1045-
pub fn load(filename: &str) -> Result<Self, TskitError> {
1046-
let tables = TableCollection::new_from_file(filename)?;
1045+
pub fn load(filename: impl AsRef<str>) -> Result<Self, TskitError> {
1046+
let tables = TableCollection::new_from_file(filename.as_ref())?;
10471047

10481048
Self::new(tables, TreeSequenceFlags::default())
10491049
}

0 commit comments

Comments
 (0)