Run rustfmt on the entire crate

This commit is contained in:
Emmanuel Gil Peyrot 2019-06-19 00:51:11 +02:00
parent 2911b9bb49
commit b0a62f25eb
4 changed files with 116 additions and 139 deletions

View File

@ -1,5 +1,5 @@
use env_logger;
use mpvipc::{Mpv, Error as MpvError};
use mpvipc::{Error as MpvError, Mpv};
fn main() -> Result<(), MpvError> {
env_logger::init();

View File

@ -1,11 +1,5 @@
use env_logger;
use mpvipc::{
Error,
Event,
Mpv,
MpvDataType,
Property,
};
use mpvipc::{Error, Event, Mpv, MpvDataType, Property};
use std::io::{self, Write};
fn seconds_to_hms(total: f64) -> String {
@ -32,8 +26,7 @@ fn main() -> Result<(), Error> {
loop {
let event = mpv.event_listen()?;
match event {
Event::PropertyChange(property) => {
match property {
Event::PropertyChange(property) => match property {
Property::Path(Some(value)) => println!("\nPlaying: {}", value),
Property::Path(None) => (),
Property::Pause(value) => pause = value,
@ -55,16 +48,25 @@ fn main() -> Result<(), Error> {
if let Some(MpvDataType::String(value)) = value.get("TRACK") {
println!(" Track: {}", value);
}
},
Property::Metadata(None) => (),
Property::Unknown { name: _, id: _, data: _ } => (),
}
Property::Metadata(None) => (),
Property::Unknown {
name: _,
id: _,
data: _,
} => (),
},
Event::Shutdown => return Ok(()),
Event::Unimplemented => panic!("Unimplemented event"),
_ => (),
}
print!("{}{} / {} ({:.0}%)\r", if pause { "(Paused) " } else { "" }, seconds_to_hms(playback_time), seconds_to_hms(duration), 100. * playback_time / duration);
print!(
"{}{} / {} ({:.0}%)\r",
if pause { "(Paused) " } else { "" },
seconds_to_hms(playback_time),
seconds_to_hms(duration),
100. * playback_time / duration
);
io::stdout().flush().unwrap();
}
}

View File

@ -1,10 +1,10 @@
use super::*;
use log::{debug, warn};
use serde_json::{self, Value};
use std::collections::HashMap;
use std::io::BufReader;
use std::io::prelude::*;
use std::io::BufReader;
use std::iter::Iterator;
use super::*;
#[derive(Debug)]
pub struct PlaylistEntry {
@ -260,8 +260,7 @@ pub fn run_mpv_command(instance: &Mpv, command: &str, args: &[&str]) -> Result<(
pub fn observe_mpv_property(instance: &Mpv, id: &isize, property: &str) -> Result<(), Error> {
let ipc_string = format!(
"{{ \"command\": [\"observe_property\", {}, \"{}\"] }}\n",
id,
property
id, property
);
match serde_json::from_str::<Value>(&send_command_sync(instance, &ipc_string)) {
Ok(feedback) => {
@ -307,7 +306,11 @@ fn try_convert_property(name: &str, id: isize, data: MpvDataType) -> Event {
},
_ => {
warn!("Property {} not implemented", name);
Property::Unknown { name: name.to_string(), id, data }
Property::Unknown {
name: name.to_string(),
id,
data,
}
}
};
Event::PropertyChange(property)

View File

@ -3,8 +3,8 @@ pub mod ipc;
use ipc::*;
use std::collections::HashMap;
use std::fmt::{self, Display};
use std::io::{BufReader, Read};
use std::os::unix::net::UnixStream;
use std::io::{Read, BufReader};
#[derive(Debug)]
pub enum Event {
@ -132,9 +132,7 @@ 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()
fmt.debug_tuple("Mpv").field(&self.name).finish()
}
}
@ -185,9 +183,7 @@ impl Display for ErrorCode {
f.write_str("The received value is not of type \'std::f64\'")
}
ErrorCode::ValueDoesNotContainHashMap => {
f.write_str(
"The received value is not of type \'std::collections::HashMap\'",
)
f.write_str("The received value is not of type \'std::collections::HashMap\'")
}
ErrorCode::ValueDoesNotContainPlaylist => {
f.write_str("The received value is not of type \'mpvipc::Playlist\'")
@ -290,9 +286,9 @@ impl Mpv {
pub fn disconnect(&self) {
let mut stream = &self.stream;
stream.shutdown(std::net::Shutdown::Both).expect(
"socket disconnect",
);
stream
.shutdown(std::net::Shutdown::Both)
.expect("socket disconnect");
let mut buffer = [0; 32];
for _ in 0..stream.bytes().count() {
stream.read(&mut buffer[..]).unwrap();
@ -449,34 +445,26 @@ impl Mpv {
option: PlaylistAddOptions,
) -> Result<(), Error> {
match file_type {
PlaylistAddTypeOptions::File => {
match option {
PlaylistAddTypeOptions::File => match option {
PlaylistAddOptions::Replace => {
run_mpv_command(self, "loadfile", &[file, "replace"])
}
PlaylistAddOptions::Append => {
run_mpv_command(self, "loadfile", &[file, "append"])
}
PlaylistAddOptions::Append => run_mpv_command(self, "loadfile", &[file, "append"]),
PlaylistAddOptions::AppendPlay => {
run_mpv_command(self, "loadfile", &[file, "append-play"])
}
}
}
},
PlaylistAddTypeOptions::Playlist => {
match option {
PlaylistAddTypeOptions::Playlist => match option {
PlaylistAddOptions::Replace => {
run_mpv_command(self, "loadlist", &[file, "replace"])
}
PlaylistAddOptions::Append |
PlaylistAddOptions::AppendPlay => {
PlaylistAddOptions::Append | PlaylistAddOptions::AppendPlay => {
run_mpv_command(self, "loadlist", &[file, "append"])
}
},
}
}
}
}
pub fn playlist_clear(&self) -> Result<(), Error> {
run_mpv_command(self, "playlist-clear", &[])
@ -492,13 +480,11 @@ impl Mpv {
pub fn playlist_play_next(&self, id: usize) -> Result<(), Error> {
match get_mpv_property::<usize>(self, "playlist-pos") {
Ok(current_id) => {
run_mpv_command(
Ok(current_id) => run_mpv_command(
self,
"playlist-move",
&[&id.to_string(), &(current_id + 1).to_string()],
)
}
),
Err(msg) => Err(msg),
}
}
@ -533,21 +519,17 @@ impl Mpv {
match option {
Switch::On => enabled = true,
Switch::Off => {}
Switch::Toggle => {
match get_mpv_property_string(self, "loop-file") {
Ok(value) => {
match value.as_ref() {
Switch::Toggle => match get_mpv_property_string(self, "loop-file") {
Ok(value) => match value.as_ref() {
"false" => {
enabled = true;
}
_ => {
enabled = false;
}
}
}
},
Err(msg) => return Err(msg),
}
}
},
}
set_mpv_property(self, "loop-file", enabled)
}
@ -557,21 +539,17 @@ impl Mpv {
match option {
Switch::On => enabled = true,
Switch::Off => {}
Switch::Toggle => {
match get_mpv_property_string(self, "loop-playlist") {
Ok(value) => {
match value.as_ref() {
Switch::Toggle => match get_mpv_property_string(self, "loop-playlist") {
Ok(value) => match value.as_ref() {
"false" => {
enabled = true;
}
_ => {
enabled = false;
}
}
}
},
Err(msg) => return Err(msg),
}
}
},
}
set_mpv_property(self, "loop-playlist", enabled)
}
@ -581,14 +559,12 @@ impl Mpv {
match option {
Switch::On => enabled = true,
Switch::Off => {}
Switch::Toggle => {
match get_mpv_property::<bool>(self, "mute") {
Switch::Toggle => match get_mpv_property::<bool>(self, "mute") {
Ok(value) => {
enabled = !value;
}
Err(msg) => return Err(msg),
}
}
},
}
set_mpv_property(self, "mute", enabled)
}
@ -627,8 +603,7 @@ impl Mpv {
pub fn set_speed(&self, input_speed: f64, option: NumberChangeOptions) -> Result<(), Error> {
match get_mpv_property::<f64>(self, "speed") {
Ok(speed) => {
match option {
Ok(speed) => match option {
NumberChangeOptions::Increase => {
set_mpv_property(self, "speed", speed + input_speed)
}
@ -638,16 +613,14 @@ impl Mpv {
}
NumberChangeOptions::Absolute => set_mpv_property(self, "speed", input_speed),
}
}
},
Err(msg) => Err(msg),
}
}
pub fn set_volume(&self, input_volume: f64, option: NumberChangeOptions) -> Result<(), Error> {
match get_mpv_property::<f64>(self, "volume") {
Ok(volume) => {
match option {
Ok(volume) => match option {
NumberChangeOptions::Increase => {
set_mpv_property(self, "volume", volume + input_volume)
}
@ -657,8 +630,7 @@ impl Mpv {
}
NumberChangeOptions::Absolute => set_mpv_property(self, "volume", input_volume),
}
}
},
Err(msg) => Err(msg),
}
}