Fix some clippy warnings.

This commit is contained in:
Paul Lietar 2016-01-02 16:48:44 +01:00
parent 90eeed3f80
commit fd6b805bfd
10 changed files with 52 additions and 49 deletions

View file

@ -70,10 +70,11 @@ impl AudioFileLoading {
let (seek_tx, seek_rx) = mpsc::channel(); let (seek_tx, seek_rx) = mpsc::channel();
let _shared = shared.clone(); {
let _session = session.clone(); let shared = shared.clone();
let session = session.clone();
thread::spawn(move || AudioFileLoading::fetch(&_session, _shared, write_file, seek_rx)); thread::spawn(move || AudioFileLoading::fetch(&session, shared, write_file, seek_rx));
}
AudioFileLoading { AudioFileLoading {
read_file: read_file, read_file: read_file,

View file

@ -36,6 +36,21 @@ impl AudioKeyManager {
} }
} }
fn send_key_request(&mut self, session: &Session, track: SpotifyId, file: FileId) -> u32 {
let seq = self.next_seq;
self.next_seq += 1;
let mut data: Vec<u8> = Vec::new();
data.write(&file.0).unwrap();
data.write(&track.to_raw()).unwrap();
data.write_u32::<BigEndian>(seq).unwrap();
data.write_u16::<BigEndian>(0x0000).unwrap();
session.send_packet(0xc, &data).unwrap();
seq
}
pub fn request(&mut self, pub fn request(&mut self,
session: &Session, session: &Session,
track: SpotifyId, track: SpotifyId,
@ -57,17 +72,7 @@ impl AudioKeyManager {
} }
}) })
.unwrap_or_else(|| { .unwrap_or_else(|| {
let seq = self.next_seq; let seq = self.send_key_request(session, track, file);
self.next_seq += 1;
let mut data: Vec<u8> = Vec::new();
data.write(&file.0).unwrap();
data.write(&track.to_raw()).unwrap();
data.write_u32::<BigEndian>(seq).unwrap();
data.write_u16::<BigEndian>(0x0000).unwrap();
session.send_packet(0xc, &data).unwrap();
self.pending.insert(seq, id.clone()); self.pending.insert(seq, id.clone());
let (tx, rx) = eventual::Future::pair(); let (tx, rx) = eventual::Future::pair();

View file

@ -75,7 +75,7 @@ impl Session {
let welcome_data: protocol::authentication::APWelcome = let welcome_data: protocol::authentication::APWelcome =
protobuf::parse_from_bytes(&data).unwrap(); protobuf::parse_from_bytes(&data).unwrap();
self.0.data.write().unwrap().canonical_username = self.0.data.write().unwrap().canonical_username =
welcome_data.get_canonical_username().to_string(); welcome_data.get_canonical_username().to_owned();
eprintln!("Authenticated !"); eprintln!("Authenticated !");
Ok(()) Ok(())

View file

@ -38,7 +38,7 @@ impl DHLocalKeys {
} }
pub fn public_key(&self) -> Vec<u8> { pub fn public_key(&self) -> Vec<u8> {
return self.public_key.to_bytes_be(); self.public_key.to_bytes_be()
} }
pub fn shared_secret(&self, remote_key: &[u8]) -> Vec<u8> { pub fn shared_secret(&self, remote_key: &[u8]) -> Vec<u8> {

View file

@ -96,7 +96,7 @@ impl DiscoveryManager {
h.result().code().to_owned() h.result().code().to_owned()
}; };
assert_eq!(mac.as_slice(), cksum); assert_eq!(&mac[..], cksum);
let decrypted = { let decrypted = {
let mut data = vec![0u8; encrypted.len()]; let mut data = vec![0u8; encrypted.len()];
@ -128,8 +128,7 @@ impl DiscoveryManager {
for mut request in server.incoming_requests() { for mut request in server.incoming_requests() {
let (_, query, _) = url::parse_path(request.url()).unwrap(); let (_, query, _) = url::parse_path(request.url()).unwrap();
let mut params = query.map(|q| url::form_urlencoded::parse(q.as_bytes())) let mut params = query.map_or(vec![], |q| url::form_urlencoded::parse(q.as_bytes()));
.unwrap_or(Vec::new());
if *request.method() == Method::Post { if *request.method() == Method::Post {
let mut body = Vec::new(); let mut body = Vec::new();

View file

@ -1,6 +1,6 @@
#![crate_name = "librespot"] #![crate_name = "librespot"]
#![feature(plugin,zero_one,iter_arith,mpsc_select,clone_from_slice,convert)] #![feature(plugin,zero_one,iter_arith,mpsc_select,clone_from_slice)]
#![plugin(protobuf_macros)] #![plugin(protobuf_macros)]
#![plugin(json_macros)] #![plugin(json_macros)]

View file

@ -142,8 +142,7 @@ impl MetadataManager {
} }
pub fn get<T: MetadataTrait>(&mut self, session: &Session, id: SpotifyId) -> MetadataRef<T> { pub fn get<T: MetadataTrait>(&mut self, session: &Session, id: SpotifyId) -> MetadataRef<T> {
let session = session.clone();
let _session = session.clone();
session.mercury(MercuryRequest { session.mercury(MercuryRequest {
method: MercuryMethod::GET, method: MercuryMethod::GET,
uri: format!("{}/{}", T::base_url(), id.to_base16()), uri: format!("{}/{}", T::base_url(), id.to_base16()),
@ -151,12 +150,10 @@ impl MetadataManager {
payload: Vec::new(), payload: Vec::new(),
}) })
.and_then(move |response| { .and_then(move |response| {
let msg: T::Message = protobuf::parse_from_bytes(response.payload let data = response.payload.first().unwrap();
.first() let msg: T::Message = protobuf::parse_from_bytes(data).unwrap();
.unwrap())
.unwrap();
Ok(T::parse(&msg, &_session)) Ok(T::parse(&msg, &session))
}) })
} }
} }

View file

@ -105,7 +105,7 @@ impl PlayerInternal {
}; };
state.position_ms = position; state.position_ms = position;
state.position_measured_at = util::now_ms(); state.position_measured_at = util::now_ms();
return true; true
}); });
drop(decoder); drop(decoder);
@ -150,7 +150,7 @@ impl PlayerInternal {
state.position_ms = position; state.position_ms = position;
state.position_measured_at = util::now_ms(); state.position_measured_at = util::now_ms();
return true; true
}); });
println!("Load Done"); println!("Load Done");
} }
@ -160,13 +160,14 @@ impl PlayerInternal {
state.position_ms = state.position_ms =
(decoder.as_mut().unwrap().time_tell().unwrap() * 1000f64) as u32; (decoder.as_mut().unwrap().time_tell().unwrap() * 1000f64) as u32;
state.position_measured_at = util::now_ms(); state.position_measured_at = util::now_ms();
return true;
true
}); });
} }
Some(PlayerCommand::Play) => { Some(PlayerCommand::Play) => {
self.update(|state| { self.update(|state| {
state.status = PlayStatus::kPlayStatusPlay; state.status = PlayStatus::kPlayStatusPlay;
return true; true
}); });
stream.start().unwrap(); stream.start().unwrap();
@ -175,7 +176,7 @@ impl PlayerInternal {
self.update(|state| { self.update(|state| {
state.status = PlayStatus::kPlayStatusPause; state.status = PlayStatus::kPlayStatusPause;
state.update_time = util::now_ms(); state.update_time = util::now_ms();
return true; true
}); });
stream.stop().unwrap(); stream.stop().unwrap();
@ -185,7 +186,7 @@ impl PlayerInternal {
if state.status == PlayStatus::kPlayStatusPlay { if state.status == PlayStatus::kPlayStatusPlay {
state.status = PlayStatus::kPlayStatusPause; state.status = PlayStatus::kPlayStatusPause;
} }
return true; true
}); });
stream.stop().unwrap(); stream.stop().unwrap();
@ -209,7 +210,7 @@ impl PlayerInternal {
self.update(|state| { self.update(|state| {
state.status = PlayStatus::kPlayStatusStop; state.status = PlayStatus::kPlayStatusStop;
state.end_of_track = true; state.end_of_track = true;
return true; true
}); });
stream.stop().unwrap(); stream.stop().unwrap();
@ -224,9 +225,10 @@ impl PlayerInternal {
state.position_ms = state.position_ms =
(decoder.as_mut().unwrap().time_tell().unwrap() * 1000f64) as u32; (decoder.as_mut().unwrap().time_tell().unwrap() * 1000f64) as u32;
state.position_measured_at = now; state.position_measured_at = now;
return true;
true
} else { } else {
return false; false
} }
}); });
} }
@ -293,24 +295,24 @@ impl SpircDelegate for Player {
} }
}); });
return update_rx; update_rx
} }
} }
impl SpircState for PlayerState { impl SpircState for PlayerState {
fn status(&self) -> PlayStatus { fn status(&self) -> PlayStatus {
return self.status; self.status
} }
fn position(&self) -> (u32, i64) { fn position(&self) -> (u32, i64) {
return (self.position_ms, self.position_measured_at); (self.position_ms, self.position_measured_at)
} }
fn update_time(&self) -> i64 { fn update_time(&self) -> i64 {
return self.update_time; self.update_time
} }
fn end_of_track(&self) -> bool { fn end_of_track(&self) -> bool {
return self.end_of_track; self.end_of_track
} }
} }

View file

@ -44,7 +44,7 @@ pub fn rand_vec<G: Rng, R: Rand>(rng: &mut G, size: usize) -> Vec<R> {
vec.push(R::rand(rng)); vec.push(R::rand(rng));
} }
return vec; vec
} }
pub mod version { pub mod version {
@ -103,17 +103,17 @@ pub fn powm(base: &BigUint, exp: &BigUint, modulus: &BigUint) -> BigUint {
base = (&base).mul(&base).rem(modulus); base = (&base).mul(&base).rem(modulus);
} }
return result; result
} }
pub struct StrChunks<'s>(&'s str, usize); pub struct StrChunks<'s>(&'s str, usize);
pub trait StrChunksExt { pub trait StrChunksExt {
fn chunks<'s>(&'s self, size: usize) -> StrChunks<'s>; fn chunks(&self, size: usize) -> StrChunks;
} }
impl StrChunksExt for str { impl StrChunksExt for str {
fn chunks<'a>(&'a self, size: usize) -> StrChunks<'a> { fn chunks(&self, size: usize) -> StrChunks {
StrChunks(self, size) StrChunks(self, size)
} }
} }

View file

@ -29,11 +29,10 @@ impl<T: Read + Seek> Seek for Subfile<T> {
}; };
let newpos = try!(self.stream.seek(pos)); let newpos = try!(self.stream.seek(pos));
if newpos > self.offset { if newpos > self.offset {
return Ok(newpos - self.offset); Ok(newpos - self.offset)
} else { } else {
return Ok(0); Ok(0)
} }
} }
} }