Skip to content

Commit

Permalink
Fix some clippy warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
plietar committed Jan 2, 2016
1 parent 90eeed3 commit fd6b805
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 49 deletions.
9 changes: 5 additions & 4 deletions src/audio_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 16 additions & 11 deletions src/audio_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
session: &Session,
track: SpotifyId,
Expand All @@ -57,17 +72,7 @@ impl AudioKeyManager {
}
})
.unwrap_or_else(|| {
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();

let seq = self.send_key_request(session, track, file);
self.pending.insert(seq, id.clone());

let (tx, rx) = eventual::Future::pair();
Expand Down
2 changes: 1 addition & 1 deletion src/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
2 changes: 1 addition & 1 deletion src/diffie_hellman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl DHLocalKeys {
}

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> {
Expand Down
5 changes: 2 additions & 3 deletions src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
11 changes: 4 additions & 7 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,18 @@ impl MetadataManager {
}

pub fn get<T: MetadataTrait>(&mut self, session: &Session, id: SpotifyId) -> MetadataRef<T> {

let _session = session.clone();
let session = session.clone();
session.mercury(MercuryRequest {
method: MercuryMethod::GET,
uri: format!("{}/{}", T::base_url(), id.to_base16()),
content_type: None,
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))
})
}
}
30 changes: 16 additions & 14 deletions src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl PlayerInternal {
};
state.position_ms = position;
state.position_measured_at = util::now_ms();
return true;
true
});
drop(decoder);

Expand Down Expand Up @@ -150,7 +150,7 @@ impl PlayerInternal {
state.position_ms = position;
state.position_measured_at = util::now_ms();

return true;
true
});
println!("Load Done");
}
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -185,7 +186,7 @@ impl PlayerInternal {
if state.status == PlayStatus::kPlayStatusPlay {
state.status = PlayStatus::kPlayStatusPause;
}
return true;
true
});

stream.stop().unwrap();
Expand All @@ -209,7 +210,7 @@ impl PlayerInternal {
self.update(|state| {
state.status = PlayStatus::kPlayStatusStop;
state.end_of_track = true;
return true;
true
});

stream.stop().unwrap();
Expand All @@ -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
}
});
}
Expand Down Expand Up @@ -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
}
}
8 changes: 4 additions & 4 deletions src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn rand_vec<G: Rng, R: Rand>(rng: &mut G, size: usize) -> Vec<R> {
vec.push(R::rand(rng));
}

return vec;
vec
}

pub mod version {
Expand Down Expand Up @@ -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)
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/util/subfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ impl<T: Read + Seek> Seek for Subfile<T> {
};

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)
}
}
}

0 comments on commit fd6b805

Please sign in to comment.