Skip to content

Commit 9d099ef

Browse files
doctortheemhtdaede
authored andcommitted
Change muxer to use AsRef<Path> arguments.
This replaces a few instances of &str representing a Path, which is not cross-platform.
1 parent 4ddc300 commit 9d099ef

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/bin/muxer/ivf.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ cfg_if::cfg_if! {
6363
}
6464

6565
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+
);
6972
io::stdout().flush().unwrap();
7073

7174
let mut option_input = String::new();
@@ -81,12 +84,14 @@ impl IvfMuxer {
8184
Ok(())
8285
}
8386

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> {
8590
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)
9095
.map_err(|e| e.context("Cannot open output file"))?,
9196
),
9297
},

src/bin/muxer/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,21 @@ pub trait Muxer: Send {
3232
fn flush(&mut self) -> io::Result<()>;
3333
}
3434

35-
pub fn create_muxer(
36-
path: &str, overwrite: bool,
35+
pub fn create_muxer<P: AsRef<Path>>(
36+
path: P, overwrite: bool,
3737
) -> Result<Box<dyn Muxer + Send>, CliError> {
3838
if !overwrite {
39-
IvfMuxer::check_file(path)?;
39+
IvfMuxer::check_file(path.as_ref())?;
4040
}
4141

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+
}
4446
}
4547

46-
let ext = Path::new(path)
48+
let ext = path
49+
.as_ref()
4750
.extension()
4851
.and_then(OsStr::to_str)
4952
.map(str::to_lowercase)

0 commit comments

Comments
 (0)