Fix many clippy lints

...and other small improvements
This commit is contained in:
johannesd3 2021-03-10 22:32:24 +01:00
parent 38761395d3
commit 5616004dbe
8 changed files with 43 additions and 49 deletions

View file

@ -56,7 +56,7 @@ ALSA
PortAudio
PulseAudio
JACK
JACK over Rodio
JACK over Rodio
SDL
Pipe
```

View file

@ -13,9 +13,6 @@ use tokio::sync::{mpsc, oneshot};
#[cfg(feature = "with-dns-sd")]
use dns_sd::DNSService;
#[cfg(not(feature = "with-dns-sd"))]
use libmdns;
use librespot_core::authentication::Credentials;
use librespot_core::config::ConnectConfig;
use librespot_core::diffie_hellman::{DH_GENERATOR, DH_PRIME};
@ -127,7 +124,7 @@ impl Discovery {
let mut h = HmacSha1::new_varkey(&checksum_key).expect("HMAC can take key of any size");
h.update(encrypted);
if let Err(_) = h.verify(cksum) {
if h.verify(cksum).is_err() {
warn!("Login error for user {:?}: MAC mismatch", username);
let result = json!({
"status": 102,

View file

@ -426,8 +426,8 @@ impl SpircTask {
Ok(dur) => dur,
Err(err) => err.duration(),
};
(dur.as_secs() as i64 + self.session.time_delta()) * 1000
+ (dur.subsec_nanos() / 1000_000) as i64
dur.as_millis() as i64 + 1000 * self.session.time_delta()
}
fn ensure_mixer_started(&mut self) {
@ -512,7 +512,9 @@ impl SpircTask {
SpircCommand::Shutdown => {
CommandSender::new(self, MessageType::kMessageTypeGoodbye).send();
self.shutdown = true;
self.commands.as_mut().map(|rx| rx.close());
if let Some(rx) = self.commands.as_mut() {
rx.close()
}
}
}
}
@ -620,7 +622,7 @@ impl SpircTask {
);
if frame.get_ident() == self.ident
|| (frame.get_recipient().len() > 0 && !frame.get_recipient().contains(&self.ident))
|| (!frame.get_recipient().is_empty() && !frame.get_recipient().contains(&self.ident))
{
return;
}
@ -639,7 +641,7 @@ impl SpircTask {
self.update_tracks(&frame);
if self.state.get_track().len() > 0 {
if !self.state.get_track().is_empty() {
let start_playing =
frame.get_state().get_status() == PlayStatus::kPlayStatusPlay;
self.load_track(start_playing, frame.get_state().get_position_ms());
@ -862,7 +864,7 @@ impl SpircTask {
fn preview_next_track(&mut self) -> Option<SpotifyId> {
self.get_track_id_to_play_from_playlist(self.state.get_playing_track_index() + 1)
.and_then(|(track_id, _)| Some(track_id))
.map(|(track_id, _)| track_id)
}
fn handle_preload_next_track(&mut self) {
@ -981,7 +983,7 @@ impl SpircTask {
};
// Reinsert queued tracks after the new playing track.
let mut pos = (new_index + 1) as usize;
for track in queue_tracks.into_iter() {
for track in queue_tracks {
self.state.mut_track().insert(pos, track);
pos += 1;
}
@ -1120,7 +1122,7 @@ impl SpircTask {
}
self.state.set_playing_track_index(index);
self.state.set_track(tracks.into_iter().cloned().collect());
self.state.set_track(tracks.iter().cloned().collect());
self.state.set_context_uri(context_uri);
// has_shuffle/repeat seem to always be true in these replace msgs,
// but to replicate the behaviour of the Android client we have to

View file

@ -192,11 +192,12 @@ impl Stream for ChannelData {
};
loop {
let x = match channel.poll_next_unpin(cx) {
let event = match channel.poll_next_unpin(cx) {
Poll::Ready(x) => x.transpose()?,
Poll::Pending => return Poll::Pending,
};
match x {
match event {
Some(ChannelEvent::Header(..)) => (),
Some(ChannelEvent::Data(data)) => return Poll::Ready(Some(Ok(data))),
None => return Poll::Ready(None),
@ -214,12 +215,12 @@ impl Stream for ChannelHeaders {
Poll::Pending => return Poll::Pending,
};
let x = match channel.poll_next_unpin(cx) {
let event = match channel.poll_next_unpin(cx) {
Poll::Ready(x) => x.transpose()?,
Poll::Pending => return Poll::Pending,
};
match x {
match event {
Some(ChannelEvent::Header(id, data)) => Poll::Ready(Some(Ok((id, data)))),
Some(ChannelEvent::Data(..)) | None => Poll::Ready(None),
}

View file

@ -104,11 +104,11 @@ where
Ok(message)
}
async fn read_into_accumulator<'a, T: AsyncRead + Unpin>(
connection: &mut T,
async fn read_into_accumulator<'a, 'b, T: AsyncRead + Unpin>(
connection: &'a mut T,
size: usize,
acc: &'a mut Vec<u8>,
) -> io::Result<&'a mut [u8]> {
acc: &'b mut Vec<u8>,
) -> io::Result<&'b mut [u8]> {
let offset = acc.len();
acc.resize(offset + size, 0);

View file

@ -42,11 +42,13 @@ impl Default for MixerConfig {
pub mod softmixer;
use self::softmixer::SoftMixer;
type MixerFn = fn(Option<MixerConfig>) -> Box<dyn Mixer>;
fn mk_sink<M: Mixer + 'static>(device: Option<MixerConfig>) -> Box<dyn Mixer> {
Box::new(M::open(device))
}
pub fn find<T: AsRef<str>>(name: Option<T>) -> Option<fn(Option<MixerConfig>) -> Box<dyn Mixer>> {
pub fn find<T: AsRef<str>>(name: Option<T>) -> Option<MixerFn> {
match name.as_ref().map(AsRef::as_ref) {
None | Some("softvol") => Some(mk_sink::<SoftMixer>),
#[cfg(feature = "alsa-backend")]

View file

@ -196,13 +196,12 @@ struct NormalisationData {
impl NormalisationData {
fn parse_from_file<T: Read + Seek>(mut file: T) -> io::Result<NormalisationData> {
const SPOTIFY_NORMALIZATION_HEADER_START_OFFSET: u64 = 144;
file.seek(SeekFrom::Start(SPOTIFY_NORMALIZATION_HEADER_START_OFFSET))
.unwrap();
file.seek(SeekFrom::Start(SPOTIFY_NORMALIZATION_HEADER_START_OFFSET))?;
let track_gain_db = file.read_f32::<LittleEndian>().unwrap();
let track_peak = file.read_f32::<LittleEndian>().unwrap();
let album_gain_db = file.read_f32::<LittleEndian>().unwrap();
let album_peak = file.read_f32::<LittleEndian>().unwrap();
let track_gain_db = file.read_f32::<LittleEndian>()?;
let track_peak = file.read_f32::<LittleEndian>()?;
let album_gain_db = file.read_f32::<LittleEndian>()?;
let album_peak = file.read_f32::<LittleEndian>()?;
let r = NormalisationData {
track_gain_db: track_gain_db,
@ -889,8 +888,7 @@ impl Future for PlayerInternal {
if !passthrough {
if let Some(ref packet) = packet {
*stream_position_pcm =
*stream_position_pcm + (packet.samples().len() / 2) as u64;
*stream_position_pcm += (packet.samples().len() / 2) as u64;
let stream_position_millis =
Self::position_pcm_to_ms(*stream_position_pcm);
@ -1111,7 +1109,9 @@ impl PlayerInternal {
editor.modify_stream(data)
}
if self.config.normalisation && normalisation_factor != 1.0 {
if self.config.normalisation
&& f32::abs(normalisation_factor - 1.0) > f32::EPSILON
{
for x in data.iter_mut() {
*x = (*x as f32 * normalisation_factor) as i16;
}
@ -1598,12 +1598,10 @@ impl PlayerInternal {
let (result_tx, result_rx) = oneshot::channel();
std::thread::spawn(move || {
futures_executor::block_on(loader.load_track(spotify_id, position_ms)).and_then(
move |data| {
let _ = result_tx.send(data);
Some(())
},
);
let data = futures_executor::block_on(loader.load_track(spotify_id, position_ms));
if let Some(data) = data {
let _ = result_tx.send(data);
}
});
result_rx.map_err(|_| ())

View file

@ -236,13 +236,7 @@ fn setup(args: &[String]) -> Setup {
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(f) => {
writeln!(
stderr(),
"error: {}\n{}",
f.to_string(),
usage(&args[0], &opts)
)
.unwrap();
eprintln!("error: {}\n{}", f.to_string(), usage(&args[0], &opts));
exit(1);
}
};
@ -360,7 +354,7 @@ fn setup(args: &[String]) -> Setup {
SessionConfig {
user_agent: version::version_string(),
device_id: device_id,
proxy: matches.opt_str("proxy").or(std::env::var("http_proxy").ok()).map(
proxy: matches.opt_str("proxy").or_else(|| std::env::var("http_proxy").ok()).map(
|s| {
match Url::parse(&s) {
Ok(url) => {
@ -390,14 +384,14 @@ fn setup(args: &[String]) -> Setup {
.opt_str("b")
.as_ref()
.map(|bitrate| Bitrate::from_str(bitrate).expect("Invalid bitrate"))
.unwrap_or(Bitrate::default());
.unwrap_or_default();
let gain_type = matches
.opt_str("normalisation-gain-type")
.as_ref()
.map(|gain_type| {
NormalisationType::from_str(gain_type).expect("Invalid normalisation type")
})
.unwrap_or(NormalisationType::default());
.unwrap_or_default();
PlayerConfig {
bitrate: bitrate,
gapless: !matches.opt_present("disable-gapless"),
@ -416,13 +410,13 @@ fn setup(args: &[String]) -> Setup {
.opt_str("device-type")
.as_ref()
.map(|device_type| DeviceType::from_str(device_type).expect("Invalid device type"))
.unwrap_or(DeviceType::default());
.unwrap_or_default();
let volume_ctrl = matches
.opt_str("volume-ctrl")
.as_ref()
.map(|volume_ctrl| VolumeCtrl::from_str(volume_ctrl).expect("Invalid volume ctrl type"))
.unwrap_or(VolumeCtrl::default());
.unwrap_or_default();
ConnectConfig {
name: name,