Skip to content

Commit 371962c

Browse files
authored
Merge pull request #20 from ahcm/main
Use &Path instead of &str for index.
2 parents 28674ea + 37337aa commit 371962c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use std::mem::MaybeUninit;
55
use std::num::NonZeroI32;
66
use std::path::Path;
77

8+
use std::os::unix::ffi::OsStrExt;
9+
810
use minimap2_sys::*;
911

1012
#[cfg(feature = "map-file")]
@@ -443,25 +445,29 @@ impl Aligner {
443445
/// // Use the previously built index
444446
/// Aligner::builder().map_ont().with_index("my_index.mmi", None);
445447
/// ```
446-
pub fn with_index(mut self, path: &str, output: Option<&str>) -> Result<Self, &'static str> {
448+
pub fn with_index<P>(mut self, path: P, output: Option<&str>) -> Result<Self, &'static str>
449+
where P: AsRef<Path>
450+
{
447451
return match self.set_index(path, output) {
448452
Ok(_) => Ok(self),
449453
Err(e) => Err(e),
450454
};
451455
}
452456

453-
pub fn set_index(&mut self, path: &str, output: Option<&str>) -> Result<(), &'static str> {
457+
pub fn set_index<P>(&mut self, path: P, output: Option<&str>) -> Result<(), &'static str>
458+
where P: AsRef<Path>
459+
{
454460
// Confirm file exists
455-
if !Path::new(path).exists() {
461+
if !path.as_ref().exists() {
456462
return Err("File does not exist");
457463
}
458464

459465
// Confirm file is not empty
460-
if Path::new(path).metadata().unwrap().len() == 0 {
466+
if path.as_ref().metadata().unwrap().len() == 0 {
461467
return Err("File is empty");
462468
}
463469

464-
let path = match std::ffi::CString::new(path) {
470+
let path = match std::ffi::CString::new(path.as_ref().as_os_str().as_bytes()) {
465471
Ok(path) => path,
466472
Err(_) => return Err("Invalid path"),
467473
};

0 commit comments

Comments
 (0)