From 979e287286e3a558e9bf47fba8c8f45bbbb54fd2 Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Tue, 5 Nov 2024 03:07:01 +0100 Subject: [PATCH] Don't pass `AsRef` params by reference (#84) --- examples/chapters.rs | 4 ++-- examples/dump-frames.rs | 2 +- examples/metadata.rs | 2 +- examples/transcode-audio.rs | 2 +- src/format/format/output.rs | 2 +- src/format/mod.rs | 22 ++++++++-------------- 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/examples/chapters.rs b/examples/chapters.rs index 0efe6fc..c1d8fe1 100644 --- a/examples/chapters.rs +++ b/examples/chapters.rs @@ -5,7 +5,7 @@ use std::env; fn main() { ffmpeg::init().unwrap(); - match ffmpeg::format::input(&env::args().nth(1).expect("missing input file name")) { + match ffmpeg::format::input(env::args().nth(1).expect("missing input file name")) { Ok(ictx) => { println!("Nb chapters: {}", ictx.nb_chapters()); @@ -20,7 +20,7 @@ fn main() { } } - let mut octx = ffmpeg::format::output(&"test.mkv").expect("Couldn't open test file"); + let mut octx = ffmpeg::format::output("test.mkv").expect("Couldn't open test file"); for chapter in ictx.chapters() { let title = match chapter.metadata().get("title") { diff --git a/examples/dump-frames.rs b/examples/dump-frames.rs index c33a31e..c76f222 100644 --- a/examples/dump-frames.rs +++ b/examples/dump-frames.rs @@ -11,7 +11,7 @@ use std::io::prelude::*; fn main() -> Result<(), ffmpeg::Error> { ffmpeg::init().unwrap(); - if let Ok(mut ictx) = input(&env::args().nth(1).expect("Cannot open file.")) { + if let Ok(mut ictx) = input(env::args().nth(1).expect("Cannot open file.")) { let input = ictx .streams() .best(Type::Video) diff --git a/examples/metadata.rs b/examples/metadata.rs index c0ee2d9..3c13e51 100644 --- a/examples/metadata.rs +++ b/examples/metadata.rs @@ -5,7 +5,7 @@ use std::env; fn main() -> Result<(), ffmpeg::Error> { ffmpeg::init().unwrap(); - match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) { + match ffmpeg::format::input(env::args().nth(1).expect("missing file")) { Ok(context) => { for (k, v) in context.metadata().iter() { println!("{k}: {v}"); diff --git a/examples/transcode-audio.rs b/examples/transcode-audio.rs index b79b5ed..5e969b3 100644 --- a/examples/transcode-audio.rs +++ b/examples/transcode-audio.rs @@ -72,7 +72,7 @@ struct Transcoder { fn transcoder>( ictx: &mut format::context::Input, octx: &mut format::context::Output, - path: &P, + path: P, filter_spec: &str, ) -> Result { let input = ictx diff --git a/src/format/format/output.rs b/src/format/format/output.rs index e874fc6..86cf6f0 100644 --- a/src/format/format/output.rs +++ b/src/format/format/output.rs @@ -57,7 +57,7 @@ impl Output { } } - pub fn codec>(self, path: &P, kind: media::Type) -> codec::Id { + pub fn codec>(self, path: P, kind: media::Type) -> codec::Id { // XXX: use to_cstring when stable let path = CString::new(path.as_ref().to_str().unwrap()).unwrap(); diff --git a/src/format/mod.rs b/src/format/mod.rs index c6913ba..a8044a1 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -36,11 +36,11 @@ pub fn license() -> &'static str { } // XXX: use to_cstring when stable -fn from_path>(path: &P) -> CString { +fn from_path>(path: P) -> CString { CString::new(path.as_ref().as_os_str().to_str().unwrap()).unwrap() } -pub fn input>(path: &P) -> Result { +pub fn input>(path: P) -> Result { unsafe { let mut ps = ptr::null_mut(); let path = from_path(path); @@ -60,7 +60,7 @@ pub fn input>(path: &P) -> Result { } pub fn input_with_dictionary>( - path: &P, + path: P, options: Dictionary, ) -> Result { unsafe { @@ -85,10 +85,7 @@ pub fn input_with_dictionary>( } } -pub fn input_with_interrupt, F>( - path: &P, - closure: F, -) -> Result +pub fn input_with_interrupt, F>(path: P, closure: F) -> Result where F: FnMut() -> bool, { @@ -111,7 +108,7 @@ where } } -pub fn output>(path: &P) -> Result { +pub fn output>(path: P) -> Result { unsafe { let mut ps = ptr::null_mut(); let path = from_path(path); @@ -127,10 +124,7 @@ pub fn output>(path: &P) -> Result { } } -pub fn output_with>( - path: &P, - options: Dictionary, -) -> Result { +pub fn output_with>(path: P, options: Dictionary) -> Result { unsafe { let mut ps = ptr::null_mut(); let path = from_path(path); @@ -159,7 +153,7 @@ pub fn output_with>( } } -pub fn output_as>(path: &P, format: &str) -> Result { +pub fn output_as>(path: P, format: &str) -> Result { unsafe { let mut ps = ptr::null_mut(); let path = from_path(path); @@ -182,7 +176,7 @@ pub fn output_as>(path: &P, format: &str) -> Result>( - path: &P, + path: P, format: &str, options: Dictionary, ) -> Result {