From 3c9b421fb4ac6979c1d232142f66577240fb8aee Mon Sep 17 00:00:00 2001 From: Clarity <82127376+clarity0@users.noreply.github.com> Date: Mon, 3 May 2021 03:23:03 +0800 Subject: [PATCH] Input: Change all Youtube-dl functions to take `AsRef` (#70) Unifies the API on all ytdl functions to remove some friction in passing in Strings, Cows, strs, and so on. Closes #57. --- src/input/restartable.rs | 9 +++++---- src/input/ytdl_src.rs | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/input/restartable.rs b/src/input/restartable.rs index 0c1c167..353affb 100644 --- a/src/input/restartable.rs +++ b/src/input/restartable.rs @@ -132,8 +132,8 @@ impl Restartable { /// /// The cost of restarting and seeking will probably be *very* high: /// expect a pause if you seek backwards. - pub async fn ytdl_search(name: &str, lazy: bool) -> Result { - Self::ytdl(format!("ytsearch1:{}", name), lazy).await + pub async fn ytdl_search(name: impl AsRef, lazy: bool) -> Result { + Self::ytdl(format!("ytsearch1:{}", name.as_ref()), lazy).await } pub(crate) fn prep_with_handle(&mut self, handle: Handle) { @@ -381,7 +381,7 @@ impl Seek for Restartable { self.position = offset; }, - Live(input, rec) => + Live(input, rec) => { if offset < self.position { // regen at given start point // We're going back in time. @@ -405,7 +405,8 @@ impl Seek for Restartable { } else { // march on with live source. self.position += input.consume(offset - self.position); - }, + } + }, Working(_, _, _, _) => { return Err(IoError::new( IoErrorKind::Interrupted, diff --git a/src/input/ytdl_src.rs b/src/input/ytdl_src.rs index 2aa3764..141cc16 100644 --- a/src/input/ytdl_src.rs +++ b/src/input/ytdl_src.rs @@ -32,8 +32,8 @@ const YOUTUBE_DL_COMMAND: &str = if cfg!(feature = "youtube-dlc") { /// Uses `youtube-dlc` if the `"youtube-dlc"` feature is enabled. /// /// [`Restartable::ytdl`]: crate::input::restartable::Restartable::ytdl -pub async fn ytdl(uri: &str) -> Result { - _ytdl(uri, &[]).await +pub async fn ytdl(uri: impl AsRef) -> Result { + _ytdl(uri.as_ref(), &[]).await } pub(crate) async fn _ytdl(uri: &str, pre_args: &[&str]) -> Result { @@ -170,6 +170,6 @@ pub(crate) async fn _ytdl_metadata(uri: &str) -> Result { /// Uses `youtube-dlc` if the `"youtube-dlc"` feature is enabled. /// /// [`Restartable::ytdl_search`]: crate::input::restartable::Restartable::ytdl_search -pub async fn ytdl_search(name: &str) -> Result { - ytdl(&format!("ytsearch1:{}", name)).await +pub async fn ytdl_search(name: impl AsRef) -> Result { + ytdl(&format!("ytsearch1:{}", name.as_ref())).await }