@@ -5,6 +5,8 @@ use std::mem::MaybeUninit;
5
5
use std:: num:: NonZeroI32 ;
6
6
use std:: path:: Path ;
7
7
8
+ use std:: os:: unix:: ffi:: OsStrExt ;
9
+
8
10
use minimap2_sys:: * ;
9
11
10
12
#[ cfg( feature = "map-file" ) ]
@@ -443,25 +445,29 @@ impl Aligner {
443
445
/// // Use the previously built index
444
446
/// Aligner::builder().map_ont().with_index("my_index.mmi", None);
445
447
/// ```
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
+ {
447
451
return match self . set_index ( path, output) {
448
452
Ok ( _) => Ok ( self ) ,
449
453
Err ( e) => Err ( e) ,
450
454
} ;
451
455
}
452
456
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
+ {
454
460
// Confirm file exists
455
- if !Path :: new ( path) . exists ( ) {
461
+ if !path. as_ref ( ) . exists ( ) {
456
462
return Err ( "File does not exist" ) ;
457
463
}
458
464
459
465
// Confirm file is not empty
460
- if Path :: new ( path) . metadata ( ) . unwrap ( ) . len ( ) == 0 {
466
+ if path. as_ref ( ) . metadata ( ) . unwrap ( ) . len ( ) == 0 {
461
467
return Err ( "File is empty" ) ;
462
468
}
463
469
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 ( ) ) {
465
471
Ok ( path) => path,
466
472
Err ( _) => return Err ( "Invalid path" ) ,
467
473
} ;
0 commit comments