Add a Debug implementation for Mpv

This commit is contained in:
Emmanuel Gil Peyrot 2019-06-18 17:34:10 +02:00
parent a14b02fb10
commit 461a87d377
1 changed files with 12 additions and 0 deletions

View File

@ -110,6 +110,7 @@ pub enum ErrorCode {
pub struct Mpv { pub struct Mpv {
stream: UnixStream, stream: UnixStream,
reader: BufReader<UnixStream>, reader: BufReader<UnixStream>,
name: String,
} }
#[derive(Debug)] #[derive(Debug)]
pub struct Playlist(pub Vec<PlaylistEntry>); pub struct Playlist(pub Vec<PlaylistEntry>);
@ -122,6 +123,14 @@ impl Drop for Mpv {
} }
} }
impl fmt::Debug for Mpv {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_tuple("Mpv")
.field(&self.name)
.finish()
}
}
impl Clone for Mpv { impl Clone for Mpv {
fn clone(&self) -> Self { fn clone(&self) -> Self {
let stream = self.stream.try_clone().expect("cloning UnixStream"); let stream = self.stream.try_clone().expect("cloning UnixStream");
@ -129,6 +138,7 @@ impl Clone for Mpv {
Mpv { Mpv {
stream, stream,
reader: BufReader::new(cloned_stream), reader: BufReader::new(cloned_stream),
name: self.name.clone(),
} }
} }
@ -138,6 +148,7 @@ impl Clone for Mpv {
*self = Mpv { *self = Mpv {
stream, stream,
reader: BufReader::new(cloned_stream), reader: BufReader::new(cloned_stream),
name: source.name.clone(),
} }
} }
} }
@ -263,6 +274,7 @@ impl Mpv {
return Ok(Mpv { return Ok(Mpv {
stream, stream,
reader: BufReader::new(cloned_stream), reader: BufReader::new(cloned_stream),
name: String::from(socket),
}); });
} }
Err(internal_error) => Err(Error(ErrorCode::ConnectError(internal_error.to_string()))), Err(internal_error) => Err(Error(ErrorCode::ConnectError(internal_error.to_string()))),