File tree Expand file tree Collapse file tree 2 files changed +22
-14
lines changed Expand file tree Collapse file tree 2 files changed +22
-14
lines changed Original file line number Diff line number Diff line change @@ -63,9 +63,12 @@ cfg_if::cfg_if! {
63
63
}
64
64
65
65
impl IvfMuxer {
66
- pub fn check_file ( path : & str ) -> Result < ( ) , CliError > {
67
- if is_file ( path) {
68
- eprint ! ( "File '{}' already exists. Overwrite ? [y/N] " , path) ;
66
+ pub fn check_file < P : AsRef < Path > > ( path : P ) -> Result < ( ) , CliError > {
67
+ if is_file ( path. as_ref ( ) ) {
68
+ eprint ! (
69
+ "File '{}' already exists. Overwrite ? [y/N] " ,
70
+ path. as_ref( ) . display( )
71
+ ) ;
69
72
io:: stdout ( ) . flush ( ) . unwrap ( ) ;
70
73
71
74
let mut option_input = String :: new ( ) ;
@@ -81,12 +84,14 @@ impl IvfMuxer {
81
84
Ok ( ( ) )
82
85
}
83
86
84
- pub fn open ( path : & str ) -> Result < Box < dyn Muxer + Send > , CliError > {
87
+ pub fn open < P : AsRef < Path > > (
88
+ path : P ,
89
+ ) -> Result < Box < dyn Muxer + Send > , CliError > {
85
90
let ivf = IvfMuxer {
86
- output : match path {
87
- "-" => Box :: new ( std:: io:: stdout ( ) ) ,
88
- f => Box :: new (
89
- File :: create ( & f )
91
+ output : match path. as_ref ( ) . to_str ( ) {
92
+ Some ( "-" ) => Box :: new ( std:: io:: stdout ( ) ) ,
93
+ _ => Box :: new (
94
+ File :: create ( path )
90
95
. map_err ( |e| e. context ( "Cannot open output file" ) ) ?,
91
96
) ,
92
97
} ,
Original file line number Diff line number Diff line change @@ -32,18 +32,21 @@ pub trait Muxer: Send {
32
32
fn flush ( & mut self ) -> io:: Result < ( ) > ;
33
33
}
34
34
35
- pub fn create_muxer (
36
- path : & str , overwrite : bool ,
35
+ pub fn create_muxer < P : AsRef < Path > > (
36
+ path : P , overwrite : bool ,
37
37
) -> Result < Box < dyn Muxer + Send > , CliError > {
38
38
if !overwrite {
39
- IvfMuxer :: check_file ( path) ?;
39
+ IvfMuxer :: check_file ( path. as_ref ( ) ) ?;
40
40
}
41
41
42
- if path == "-" {
43
- return IvfMuxer :: open ( path) ;
42
+ if let Some ( path) = path. as_ref ( ) . to_str ( ) {
43
+ if path == "-" {
44
+ return IvfMuxer :: open ( path) ;
45
+ }
44
46
}
45
47
46
- let ext = Path :: new ( path)
48
+ let ext = path
49
+ . as_ref ( )
47
50
. extension ( )
48
51
. and_then ( OsStr :: to_str)
49
52
. map ( str:: to_lowercase)
You can’t perform that action at this time.
0 commit comments