Skip to content

Commit f00f019

Browse files
authored
Merge pull request kstep#14 from tomprince/rustfmt
Run rustfmt in travis.
2 parents 1302568 + b572296 commit f00f019

24 files changed

+219
-247
lines changed

.travis.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
sudo: required
22
language: rust
3+
cache: cargo
34
addons:
45
apt:
56
packages:
@@ -16,10 +17,16 @@ before_script:
1617
- |
1718
pip install 'travis-cargo<0.2' --user &&
1819
export PATH=$HOME/.local/bin:$PATH
20+
- |
21+
cargo install --force rustfmt
22+
export PATH=$HOME/.cargo/bin:$PATH
1923
script:
2024
- |
2125
travis-cargo build &&
22-
travis-cargo test &&
26+
travis-cargo test
27+
- |
28+
cargo fmt -- --write-mode diff
29+
- |
2330
travis-cargo --only stable doc
2431
after_success:
2532
- travis-cargo coveralls --no-sudo --verify

benches/helpers.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
extern crate mpd;
22

3-
use std::net::TcpStream;
43
use std::env;
4+
use std::net::TcpStream;
55

66
pub fn connect() -> mpd::Client<TcpStream> {
77
let addr = env::var("MPD_SOCK").unwrap_or("127.0.0.1:6600".to_owned());
88
mpd::Client::connect(&*addr).unwrap()
99
}
10-

benches/options.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ extern crate unix_socket;
77

88
mod helpers;
99
use helpers::connect;
10-
use time::Duration;
1110
use test::{Bencher, black_box};
11+
use time::Duration;
1212
use unix_socket::UnixStream;
1313

1414
#[bench]
1515
fn status(b: &mut Bencher) {
1616
let mut mpd = mpd::Client::<UnixStream>::new(UnixStream::connect("/var/run/mpd/socket").unwrap()).unwrap();
17-
b.iter(|| {
18-
black_box(mpd.status());
19-
});
17+
b.iter(|| { black_box(mpd.status()); });
2018
}

examples/example.rs

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,10 @@
11
extern crate mpd;
22

3-
use std::net::TcpStream;
43
use mpd::Client;
5-
//use mpd::playlists::MpdPlaylist;
6-
//use mpd::outputs::MpdOutput;
7-
//use mpd::idle::{MpdEvent, PLAYER, UPDATE};
8-
//use rustc_serialize::json;
9-
//use std::str::from_str;
4+
use std::net::TcpStream;
105

116
fn main() {
127
let mut c = Client::new(TcpStream::connect("127.0.0.1:6600").unwrap()).unwrap();
138
println!("version: {:?}", c.version);
149
println!("status: {:?}", c.status());
15-
//println!("stats: {:?}", c.stats());
16-
////println!("song: {:?}", c.current_song());
17-
//println!("queue: {:?}", c.queue());
18-
//println!("outputs: {:?}", c.outputs());
19-
20-
//println!("playlists:");
21-
//for pl in c.playlists().unwrap().iter() {
22-
//println!("{:?}", pl);
23-
//println!("{:?}", pl.songs(&mut c));
24-
//}
25-
26-
////let conn = match c {
27-
////None => panic!("connection is None"),
28-
////Some(Err(e)) => panic!("connection error: {}", e),
29-
////Some(Ok(c)) => c
30-
////};
31-
32-
//////println!("{}", json::encode(&conn.status()));
33-
//////println!("{}", json::encode(&conn.stats()));
34-
////println!("{}", json::encode(&conn.playlists()));
35-
////println!("{}", json::encode(&conn.outputs()));
36-
//////println!("{}", json::encode(&conn.queue().songs()));
37-
38-
////for mut out in conn.outputs().unwrap().map(|v| v.unwrap()) {
39-
////println!("enabling {}", out.enable(true));
40-
////}
41-
42-
//////println!("{}", conn.stop());
43-
44-
//////println!("{}", conn.current_song());
45-
46-
////let v = conn.version();
47-
////println!("version: {}", v);
48-
49-
//////for e in conn.wait(None) {
50-
//////match e {
51-
//////Err(ref v) => panic!("{}", v),
52-
//////Ok(ref v) => println!("{}", v)
53-
//////}
54-
//////}
5510
}

src/client.rs

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44
//!
55
//! [proto]: http://www.musicpd.org/doc/protocol/
66
7-
use std::io::{BufRead, Lines, Read, Write};
8-
use std::convert::From;
9-
use std::fmt::Arguments;
10-
use std::net::{TcpStream, ToSocketAddrs};
117

128
use bufstream::BufStream;
13-
use version::Version;
9+
10+
use convert::*;
1411
use error::{Error, ProtoError, Result};
15-
use status::{ReplayGain, Status};
16-
use stats::Stats;
17-
use song::{Id, Song};
12+
use message::{Channel, Message};
13+
use mount::{Mount, Neighbor};
1814
use output::Output;
1915
use playlist::Playlist;
2016
use plugin::Plugin;
21-
use message::{Channel, Message};
22-
use search::Query;
23-
use mount::{Mount, Neighbor};
24-
25-
use convert::*;
2617
use proto::*;
18+
use search::Query;
19+
use song::{Id, Song};
20+
use stats::Stats;
21+
use status::{ReplayGain, Status};
22+
use std::convert::From;
23+
use std::fmt::Arguments;
24+
use std::io::{BufRead, Lines, Read, Write};
25+
use std::net::{TcpStream, ToSocketAddrs};
26+
use version::Version;
2727

2828
// Client {{{
2929

@@ -453,7 +453,11 @@ impl<S: Read + Write> Client<S> {
453453

454454
/// Set given output enabled state
455455
pub fn output<T: ToOutputId>(&mut self, id: T, state: bool) -> Result<()> {
456-
if state { self.out_enable(id) } else { self.out_disable(id) }
456+
if state {
457+
self.out_enable(id)
458+
} else {
459+
self.out_disable(id)
460+
}
457461
}
458462

459463
/// Disable given output
@@ -490,8 +494,8 @@ impl<S: Read + Write> Client<S> {
490494
self.read_pairs()
491495
.filter(|r| {
492496
r.as_ref()
493-
.map(|&(ref a, _)| *a == "command")
494-
.unwrap_or(true)
497+
.map(|&(ref a, _)| *a == "command")
498+
.unwrap_or(true)
495499
})
496500
.map(|r| r.map(|(_, b)| b))
497501
.collect()
@@ -505,8 +509,8 @@ impl<S: Read + Write> Client<S> {
505509
self.read_pairs()
506510
.filter(|r| {
507511
r.as_ref()
508-
.map(|&(ref a, _)| *a == "command")
509-
.unwrap_or(true)
512+
.map(|&(ref a, _)| *a == "command")
513+
.unwrap_or(true)
510514
})
511515
.map(|r| r.map(|(_, b)| b))
512516
.collect()
@@ -520,8 +524,8 @@ impl<S: Read + Write> Client<S> {
520524
self.read_pairs()
521525
.filter(|r| {
522526
r.as_ref()
523-
.map(|&(ref a, _)| *a == "handler")
524-
.unwrap_or(true)
527+
.map(|&(ref a, _)| *a == "handler")
528+
.unwrap_or(true)
525529
})
526530
.map(|r| r.map(|(_, b)| b))
527531
.collect()
@@ -535,8 +539,8 @@ impl<S: Read + Write> Client<S> {
535539
self.read_pairs()
536540
.filter(|r| {
537541
r.as_ref()
538-
.map(|&(ref a, _)| *a == "tagtype")
539-
.unwrap_or(true)
542+
.map(|&(ref a, _)| *a == "tagtype")
543+
.unwrap_or(true)
540544
})
541545
.map(|r| r.map(|(_, b)| b))
542546
.collect()
@@ -583,8 +587,8 @@ impl<S: Read + Write> Client<S> {
583587
self.read_pairs()
584588
.filter(|r| {
585589
r.as_ref()
586-
.map(|&(ref a, _)| *a == "channel")
587-
.unwrap_or(true)
590+
.map(|&(ref a, _)| *a == "channel")
591+
.unwrap_or(true)
588592
})
589593
.map(|r| r.map(|(_, b)| unsafe { Channel::new_unchecked(b) }))
590594
.collect()
@@ -681,8 +685,8 @@ impl<S: Read + Write> Client<S> {
681685
self.read_pairs()
682686
.filter(|r| {
683687
r.as_ref()
684-
.map(|&(ref a, _)| *a == "sticker")
685-
.unwrap_or(true)
688+
.map(|&(ref a, _)| *a == "sticker")
689+
.unwrap_or(true)
686690
})
687691
.map(|r| r.map(|(_, b)| b.splitn(2, "=").nth(1).map(|s| s.to_owned()).unwrap()))
688692
.collect()
@@ -700,8 +704,8 @@ impl<S: Read + Write> Client<S> {
700704
rmap.map(|mut map| {
701705
(map.remove("file").unwrap(),
702706
map.remove("sticker")
703-
.and_then(|s| s.splitn(2, "=").nth(1).map(|s| s.to_owned()))
704-
.unwrap())
707+
.and_then(|s| s.splitn(2, "=").nth(1).map(|s| s.to_owned()))
708+
.unwrap())
705709
})
706710
})
707711
.collect()
@@ -716,8 +720,8 @@ impl<S: Read + Write> Client<S> {
716720
self.read_pairs()
717721
.filter(|r| {
718722
r.as_ref()
719-
.map(|&(ref a, _)| *a == "file")
720-
.unwrap_or(true)
723+
.map(|&(ref a, _)| *a == "file")
724+
.unwrap_or(true)
721725
})
722726
.map(|r| r.map(|(_, b)| b))
723727
.collect()

src/convert.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#![allow(missing_docs)]
22
//! These are inner traits to support methods overloading for the `Client`
33
4+
use error::Error;
5+
use output::Output;
6+
use playlist::Playlist;
7+
use song::{self, Id, Song};
48
use std::collections::BTreeMap;
59
use std::ops::{Range, RangeFrom, RangeFull, RangeTo};
610

711
use time::Duration;
8-
use output::Output;
9-
use playlist::Playlist;
10-
use song::{self, Id, Song};
11-
use error::Error;
1212

1313
#[doc(hidden)]
1414
pub trait FromMap: Sized {

src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
//!
1313
//! This module defines all necessary infrastructure to represent these kinds or errors.
1414
15-
use time::ParseError as TimeParseError;
1615
use std::convert::From;
17-
use std::io::Error as IoError;
1816
use std::error::Error as StdError;
19-
use std::str::FromStr;
2017
use std::fmt;
18+
use std::io::Error as IoError;
2119
use std::num::{ParseFloatError, ParseIntError};
2220
use std::result;
21+
use std::str::FromStr;
22+
use time::ParseError as TimeParseError;
2323

2424
// Server errors {{{
2525
/// Server error codes, as defined in [libmpdclient](http://www.musicpd.org/doc/libmpdclient/protocol_8h_source.html)

src/idle.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
//! to original `Client` struct, thus enforcing MPD contract in regards of (im)possibility
2727
//! to send commands while in "idle" mode.
2828
29-
use std::fmt;
30-
use std::str::FromStr;
31-
use std::io::{Read, Write};
32-
use std::mem::forget;
29+
use client::Client;
3330

3431
use error::{Error, ParseError};
35-
use client::Client;
3632
use proto::Proto;
33+
use std::fmt;
34+
use std::io::{Read, Write};
35+
use std::mem::forget;
36+
use std::str::FromStr;
3737

3838
/// Subsystems for `idle` command
3939
#[derive(Clone, Copy, Debug, PartialEq, RustcEncodable)]
@@ -111,14 +111,14 @@ impl<'a, S: 'a + Read + Write> IdleGuard<'a, S> {
111111
/// Get list of subsystems with new events, interrupting idle mode in process
112112
pub fn get(self) -> Result<Vec<Subsystem>, Error> {
113113
let result = self.0
114-
.read_pairs()
115-
.filter(|r| {
116-
r.as_ref()
117-
.map(|&(ref a, _)| *a == "changed")
118-
.unwrap_or(true)
119-
})
120-
.map(|r| r.and_then(|(_, b)| b.parse().map_err(From::from)))
121-
.collect();
114+
.read_pairs()
115+
.filter(|r| {
116+
r.as_ref()
117+
.map(|&(ref a, _)| *a == "changed")
118+
.unwrap_or(true)
119+
})
120+
.map(|r| r.and_then(|(_, b)| b.parse().map_err(From::from)))
121+
.collect();
122122
forget(self);
123123
result
124124
}
@@ -165,9 +165,9 @@ impl<S: Read + Write> Idle for Client<S> {
165165
type Stream = S;
166166
fn idle<'a>(&'a mut self, subsystems: &[Subsystem]) -> Result<IdleGuard<'a, S>, Error> {
167167
let subsystems = subsystems.iter()
168-
.map(|v| v.to_string())
169-
.collect::<Vec<String>>()
170-
.join(" ");
168+
.map(|v| v.to_string())
169+
.collect::<Vec<String>>()
170+
.join(" ");
171171
try!(self.run_command_fmt(format_args!("idle {}", subsystems)));
172172
Ok(IdleGuard(self))
173173
}

src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ mod proto;
5656
pub mod client;
5757

5858
pub use client::Client;
59-
pub use status::{ReplayGain, State, Status};
60-
pub use version::Version;
61-
pub use song::{Id, Song};
62-
pub use playlist::Playlist;
59+
pub use idle::{Idle, Subsystem};
60+
pub use message::{Channel, Message};
61+
pub use mount::{Mount, Neighbor};
6362
pub use output::Output;
63+
pub use playlist::Playlist;
6464
pub use plugin::Plugin;
65-
pub use stats::Stats;
6665
pub use search::{Query, Term};
67-
pub use message::{Channel, Message};
68-
pub use idle::{Idle, Subsystem};
69-
pub use mount::{Mount, Neighbor};
66+
pub use song::{Id, Song};
67+
pub use stats::Stats;
68+
pub use status::{ReplayGain, State, Status};
69+
pub use version::Version;

0 commit comments

Comments
 (0)