Skip to content

Commit 148ef03

Browse files
committed
Use SongPath for adding songs to the queue.
1 parent 0d54a9c commit 148ef03

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

src/client.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ impl<S: Read + Write> Client<S> {
237237
}
238238

239239
/// Append a song into a queue
240-
pub fn push<P: AsRef<str>>(&mut self, path: P) -> Result<Id> {
241-
self.run_command("addid", path.as_ref())
240+
pub fn push<P: ToSongPath>(&mut self, path: P) -> Result<Id> {
241+
self.run_command("addid", path)
242242
.and_then(|_| self.read_field("Id"))
243243
.and_then(|v| {
244244
self.expect_ok()
@@ -247,8 +247,8 @@ impl<S: Read + Write> Client<S> {
247247
}
248248

249249
/// Insert a song into a given position in a queue
250-
pub fn insert<P: AsRef<str>>(&mut self, path: P, pos: usize) -> Result<usize> {
251-
self.run_command("addid", (path.as_ref(), pos))
250+
pub fn insert<P: ToSongPath>(&mut self, path: P, pos: usize) -> Result<usize> {
251+
self.run_command("addid", (path, pos))
252252
.and_then(|_| self.read_field("Id"))
253253
.and_then(|v| {
254254
self.expect_ok()
@@ -383,8 +383,8 @@ impl<S: Read + Write> Client<S> {
383383
}
384384

385385
/// Add new songs to a playlist
386-
pub fn pl_push<N: ToPlaylistName, P: AsRef<str>>(&mut self, name: N, path: P) -> Result<()> {
387-
self.run_command("playlistadd", (name.to_name(), path.as_ref()))
386+
pub fn pl_push<N: ToPlaylistName, P: ToSongPath>(&mut self, name: N, path: P) -> Result<()> {
387+
self.run_command("playlistadd", (name.to_name(), path))
388388
.and_then(|_| self.expect_ok())
389389
}
390390

src/convert.rs

+32
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use error::Error;
55
use output::Output;
66
use playlist::Playlist;
7+
use proto::ToArguments;
78
use song::{self, Id, Song};
89
use std::collections::BTreeMap;
910
use std::ops::{Range, RangeFrom, RangeFull, RangeTo};
@@ -281,4 +282,35 @@ impl ToSongRange for song::Range {
281282
self
282283
}
283284
}
285+
284286
// }}}
287+
288+
pub trait ToSongPath {
289+
fn to_path(&self) -> &str;
290+
}
291+
292+
impl ToSongPath for Song {
293+
fn to_path(&self) -> &str {
294+
&self.file
295+
}
296+
}
297+
298+
impl<'a, T: ToSongPath> ToSongPath for &'a T {
299+
fn to_path(&self) -> &str {
300+
(*self).to_path()
301+
}
302+
}
303+
304+
impl ToSongPath for AsRef<str> {
305+
fn to_path(&self) -> &str {
306+
self.as_ref()
307+
}
308+
}
309+
310+
impl<T: ToSongPath> ToArguments for T {
311+
fn to_arguments<F, E>(&self, f: &mut F) -> Result<(), E>
312+
where F: FnMut(&str) -> Result<(), E>
313+
{
314+
self.to_path().to_arguments(f)
315+
}
316+
}

0 commit comments

Comments
 (0)