From fd6b805bfd5b86ba2b932283716942d1082cf4bf Mon Sep 17 00:00:00 2001 From: Paul Lietar Date: Sat, 2 Jan 2016 16:48:44 +0100 Subject: [PATCH] Fix some clippy warnings. --- src/audio_file.rs | 9 +++++---- src/audio_key.rs | 27 ++++++++++++++++----------- src/authentication.rs | 2 +- src/diffie_hellman.rs | 2 +- src/discovery.rs | 5 ++--- src/lib.rs | 2 +- src/metadata.rs | 11 ++++------- src/player.rs | 30 ++++++++++++++++-------------- src/util/mod.rs | 8 ++++---- src/util/subfile.rs | 5 ++--- 10 files changed, 52 insertions(+), 49 deletions(-) diff --git a/src/audio_file.rs b/src/audio_file.rs index 2c4d9332..c9ba3ea2 100644 --- a/src/audio_file.rs +++ b/src/audio_file.rs @@ -70,10 +70,11 @@ impl AudioFileLoading { let (seek_tx, seek_rx) = mpsc::channel(); - let _shared = shared.clone(); - let _session = session.clone(); - - thread::spawn(move || AudioFileLoading::fetch(&_session, _shared, write_file, seek_rx)); + { + let shared = shared.clone(); + let session = session.clone(); + thread::spawn(move || AudioFileLoading::fetch(&session, shared, write_file, seek_rx)); + } AudioFileLoading { read_file: read_file, diff --git a/src/audio_key.rs b/src/audio_key.rs index fed7c2fd..ade12997 100644 --- a/src/audio_key.rs +++ b/src/audio_key.rs @@ -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 = Vec::new(); + data.write(&file.0).unwrap(); + data.write(&track.to_raw()).unwrap(); + data.write_u32::(seq).unwrap(); + data.write_u16::(0x0000).unwrap(); + + session.send_packet(0xc, &data).unwrap(); + + seq + } + pub fn request(&mut self, session: &Session, track: SpotifyId, @@ -57,17 +72,7 @@ impl AudioKeyManager { } }) .unwrap_or_else(|| { - let seq = self.next_seq; - self.next_seq += 1; - - let mut data: Vec = Vec::new(); - data.write(&file.0).unwrap(); - data.write(&track.to_raw()).unwrap(); - data.write_u32::(seq).unwrap(); - data.write_u16::(0x0000).unwrap(); - - session.send_packet(0xc, &data).unwrap(); - + let seq = self.send_key_request(session, track, file); self.pending.insert(seq, id.clone()); let (tx, rx) = eventual::Future::pair(); diff --git a/src/authentication.rs b/src/authentication.rs index 6fc670e7..f927850b 100644 --- a/src/authentication.rs +++ b/src/authentication.rs @@ -75,7 +75,7 @@ impl Session { let welcome_data: protocol::authentication::APWelcome = protobuf::parse_from_bytes(&data).unwrap(); self.0.data.write().unwrap().canonical_username = - welcome_data.get_canonical_username().to_string(); + welcome_data.get_canonical_username().to_owned(); eprintln!("Authenticated !"); Ok(()) diff --git a/src/diffie_hellman.rs b/src/diffie_hellman.rs index 5866716f..20c2dc44 100644 --- a/src/diffie_hellman.rs +++ b/src/diffie_hellman.rs @@ -38,7 +38,7 @@ impl DHLocalKeys { } pub fn public_key(&self) -> Vec { - return self.public_key.to_bytes_be(); + self.public_key.to_bytes_be() } pub fn shared_secret(&self, remote_key: &[u8]) -> Vec { diff --git a/src/discovery.rs b/src/discovery.rs index c361029e..3449245d 100644 --- a/src/discovery.rs +++ b/src/discovery.rs @@ -96,7 +96,7 @@ impl DiscoveryManager { h.result().code().to_owned() }; - assert_eq!(mac.as_slice(), cksum); + assert_eq!(&mac[..], cksum); let decrypted = { let mut data = vec![0u8; encrypted.len()]; @@ -128,8 +128,7 @@ impl DiscoveryManager { for mut request in server.incoming_requests() { let (_, query, _) = url::parse_path(request.url()).unwrap(); - let mut params = query.map(|q| url::form_urlencoded::parse(q.as_bytes())) - .unwrap_or(Vec::new()); + let mut params = query.map_or(vec![], |q| url::form_urlencoded::parse(q.as_bytes())); if *request.method() == Method::Post { let mut body = Vec::new(); diff --git a/src/lib.rs b/src/lib.rs index 11535cc0..586f4336 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ #![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(json_macros)] diff --git a/src/metadata.rs b/src/metadata.rs index dbc34ab0..d3ac8b00 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -142,8 +142,7 @@ impl MetadataManager { } pub fn get(&mut self, session: &Session, id: SpotifyId) -> MetadataRef { - - let _session = session.clone(); + let session = session.clone(); session.mercury(MercuryRequest { method: MercuryMethod::GET, uri: format!("{}/{}", T::base_url(), id.to_base16()), @@ -151,12 +150,10 @@ impl MetadataManager { payload: Vec::new(), }) .and_then(move |response| { - let msg: T::Message = protobuf::parse_from_bytes(response.payload - .first() - .unwrap()) - .unwrap(); + let data = response.payload.first().unwrap(); + let msg: T::Message = protobuf::parse_from_bytes(data).unwrap(); - Ok(T::parse(&msg, &_session)) + Ok(T::parse(&msg, &session)) }) } } diff --git a/src/player.rs b/src/player.rs index d02103e3..23564b13 100644 --- a/src/player.rs +++ b/src/player.rs @@ -105,7 +105,7 @@ impl PlayerInternal { }; state.position_ms = position; state.position_measured_at = util::now_ms(); - return true; + true }); drop(decoder); @@ -150,7 +150,7 @@ impl PlayerInternal { state.position_ms = position; state.position_measured_at = util::now_ms(); - return true; + true }); println!("Load Done"); } @@ -160,13 +160,14 @@ impl PlayerInternal { state.position_ms = (decoder.as_mut().unwrap().time_tell().unwrap() * 1000f64) as u32; state.position_measured_at = util::now_ms(); - return true; + + true }); } Some(PlayerCommand::Play) => { self.update(|state| { state.status = PlayStatus::kPlayStatusPlay; - return true; + true }); stream.start().unwrap(); @@ -175,7 +176,7 @@ impl PlayerInternal { self.update(|state| { state.status = PlayStatus::kPlayStatusPause; state.update_time = util::now_ms(); - return true; + true }); stream.stop().unwrap(); @@ -185,7 +186,7 @@ impl PlayerInternal { if state.status == PlayStatus::kPlayStatusPlay { state.status = PlayStatus::kPlayStatusPause; } - return true; + true }); stream.stop().unwrap(); @@ -209,7 +210,7 @@ impl PlayerInternal { self.update(|state| { state.status = PlayStatus::kPlayStatusStop; state.end_of_track = true; - return true; + true }); stream.stop().unwrap(); @@ -224,9 +225,10 @@ impl PlayerInternal { state.position_ms = (decoder.as_mut().unwrap().time_tell().unwrap() * 1000f64) as u32; state.position_measured_at = now; - return true; + + true } else { - return false; + false } }); } @@ -293,24 +295,24 @@ impl SpircDelegate for Player { } }); - return update_rx; + update_rx } } impl SpircState for PlayerState { fn status(&self) -> PlayStatus { - return self.status; + self.status } 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 { - return self.update_time; + self.update_time } fn end_of_track(&self) -> bool { - return self.end_of_track; + self.end_of_track } } diff --git a/src/util/mod.rs b/src/util/mod.rs index 23adeaaa..ee584f62 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -44,7 +44,7 @@ pub fn rand_vec(rng: &mut G, size: usize) -> Vec { vec.push(R::rand(rng)); } - return vec; + vec } pub mod version { @@ -103,17 +103,17 @@ pub fn powm(base: &BigUint, exp: &BigUint, modulus: &BigUint) -> BigUint { base = (&base).mul(&base).rem(modulus); } - return result; + result } pub struct StrChunks<'s>(&'s str, usize); pub trait StrChunksExt { - fn chunks<'s>(&'s self, size: usize) -> StrChunks<'s>; + fn chunks(&self, size: usize) -> StrChunks; } impl StrChunksExt for str { - fn chunks<'a>(&'a self, size: usize) -> StrChunks<'a> { + fn chunks(&self, size: usize) -> StrChunks { StrChunks(self, size) } } diff --git a/src/util/subfile.rs b/src/util/subfile.rs index 36d9bf1d..81d5d916 100644 --- a/src/util/subfile.rs +++ b/src/util/subfile.rs @@ -29,11 +29,10 @@ impl Seek for Subfile { }; let newpos = try!(self.stream.seek(pos)); - if newpos > self.offset { - return Ok(newpos - self.offset); + Ok(newpos - self.offset) } else { - return Ok(0); + Ok(0) } } }