From: Thomas Karpiniec Date: Mon, 27 Jan 2025 09:19:26 +0000 (+1100) Subject: Address more clippy lints X-Git-Tag: v0.1.0~2 X-Git-Url: https://code.octet-stream.net/m17rt/commitdiff_plain/bc6fb90d7053082e7aaf261f4da8905c49e9fe01?hp=eca97054b9edb6258d1392240d12b0772a10f20d Address more clippy lints --- diff --git a/m17app/src/app.rs b/m17app/src/app.rs index 7d363dd..ae01976 100644 --- a/m17app/src/app.rs +++ b/m17app/src/app.rs @@ -92,7 +92,7 @@ impl TxHandle { } let mut full_payload = vec![]; full_payload.extend_from_slice(&pack_type[0..pack_type_len]); - full_payload.extend_from_slice(&payload); + full_payload.extend_from_slice(payload); let crc = m17core::crc::m17_crc(&full_payload); full_payload.extend_from_slice(&crc.to_be_bytes()); let kiss_frame = KissFrame::new_full_packet(&link_setup.raw.0, &full_payload).unwrap(); @@ -107,7 +107,7 @@ impl TxHandle { // as long as there is only one TNC it is implied there is only ever one stream transmission in flight pub fn transmit_stream_next(&self, stream: &StreamFrame) { - let kiss_frame = KissFrame::new_stream_data(&stream).unwrap(); + let kiss_frame = KissFrame::new_stream_data(stream).unwrap(); let _ = self.event_tx.send(TncControlEvent::Kiss(kiss_frame)); } } @@ -133,6 +133,7 @@ impl Adapters { } /// Carries a request from a method on M17App to the TNC's writer thread, which will execute it. +#[allow(clippy::large_enum_variant)] enum TncControlEvent { Kiss(KissFrame), Start, @@ -144,8 +145,8 @@ fn spawn_reader(mut tnc: T, adapters: Arc>) { let mut kiss_buffer = KissBuffer::new(); let mut stream_running = false; loop { - let mut buf = kiss_buffer.buf_remaining(); - let n = match tnc.read(&mut buf) { + let buf = kiss_buffer.buf_remaining(); + let n = match tnc.read(buf) { Ok(n) => n, Err(_) => break, }; @@ -200,7 +201,7 @@ fn spawn_reader(mut tnc: T, adapters: Arc>) { for s in subs { s.packet_received( LinkSetup::new_raw(lsf.clone()), - packet_type.clone(), + packet_type, packet_payload.clone(), ); } @@ -260,7 +261,7 @@ fn spawn_writer(mut tnc: T, event_rx: mpsc::Receiver) { while let Ok(ev) = event_rx.recv() { match ev { TncControlEvent::Kiss(k) => { - if let Err(e) = tnc.write_all(&k.as_bytes()) { + if let Err(e) = tnc.write_all(k.as_bytes()) { debug!("kiss send err: {:?}", e); return; } diff --git a/m17app/src/soundcard.rs b/m17app/src/soundcard.rs index b12ef88..3914632 100644 --- a/m17app/src/soundcard.rs +++ b/m17app/src/soundcard.rs @@ -63,10 +63,7 @@ impl Soundcard { continue; }; if configs - .find(|config| { - config.channels() == 1 && config.sample_format() == SampleFormat::I16 - }) - .is_some() + .any(|config| config.channels() == 1 && config.sample_format() == SampleFormat::I16) { let Ok(name) = d.name() else { continue; @@ -89,10 +86,7 @@ impl Soundcard { continue; }; if configs - .find(|config| { - config.channels() == 1 && config.sample_format() == SampleFormat::I16 - }) - .is_some() + .any(|config| config.channels() == 1 && config.sample_format() == SampleFormat::I16) { let Ok(name) = d.name() else { continue; diff --git a/m17app/src/soundmodem.rs b/m17app/src/soundmodem.rs index 2d005b1..974fd45 100644 --- a/m17app/src/soundmodem.rs +++ b/m17app/src/soundmodem.rs @@ -277,7 +277,7 @@ impl InputSource for InputRrcFile { if let Err(e) = samples.try_send(SoundmodemEvent::BasebandInput(buf.into())) { debug!("overflow feeding soundmodem: {e:?}"); } - next_tick = next_tick + TICK; + next_tick += TICK; idx = 0; std::thread::sleep(next_tick.duration_since(Instant::now())); } @@ -317,7 +317,7 @@ impl InputSource for NullInputSource { loop { std::thread::sleep(next_tick.duration_since(Instant::now())); - next_tick = next_tick + TICK; + next_tick += TICK; if end_rx.try_recv() != Err(TryRecvError::Empty) { break; } @@ -336,6 +336,12 @@ impl InputSource for NullInputSource { } } +impl Default for NullInputSource { + fn default() -> Self { + Self::new() + } +} + pub struct OutputBuffer { pub idling: bool, // TODO: something more efficient @@ -353,6 +359,12 @@ impl OutputBuffer { } } +impl Default for OutputBuffer { + fn default() -> Self { + Self::new() + } +} + pub trait OutputSink: Send + Sync + 'static { fn start(&self, event_tx: SyncSender, buffer: Arc>); fn close(&self); @@ -390,7 +402,7 @@ impl OutputSink for OutputRrcFile { loop { std::thread::sleep(next_tick.duration_since(Instant::now())); - next_tick = next_tick + TICK; + next_tick += TICK; if end_rx.try_recv() != Err(TryRecvError::Empty) { break; } @@ -440,6 +452,12 @@ impl NullOutputSink { } } +impl Default for NullOutputSink { + fn default() -> Self { + Self::new() + } +} + impl OutputSink for NullOutputSink { fn start(&self, event_tx: SyncSender, buffer: Arc>) { let (end_tx, end_rx) = channel(); @@ -451,7 +469,7 @@ impl OutputSink for NullOutputSink { loop { std::thread::sleep(next_tick.duration_since(Instant::now())); - next_tick = next_tick + TICK; + next_tick += TICK; if end_rx.try_recv() != Err(TryRecvError::Empty) { break; } @@ -459,7 +477,7 @@ impl OutputSink for NullOutputSink { let mut buffer = buffer.write().unwrap(); let mut taken = 0; for _ in 0..SAMPLES_PER_TICK { - if !buffer.samples.pop_front().is_some() { + if buffer.samples.pop_front().is_none() { if !buffer.idling { debug!("null output had underrun"); let _ = event_tx.send(SoundmodemEvent::OutputUnderrun); @@ -497,6 +515,12 @@ impl NullPtt { } } +impl Default for NullPtt { + fn default() -> Self { + Self::new() + } +} + impl Ptt for NullPtt { fn ptt_on(&mut self) {} fn ptt_off(&mut self) {} diff --git a/m17codec2/src/lib.rs b/m17codec2/src/lib.rs index 016acc7..1d05f27 100755 --- a/m17codec2/src/lib.rs +++ b/m17codec2/src/lib.rs @@ -61,6 +61,12 @@ impl Codec2Adapter { } } +impl Default for Codec2Adapter { + fn default() -> Self { + Self::new() + } +} + struct AdapterState { tx: Option, /// Circular buffer of output samples for playback @@ -183,8 +189,8 @@ impl WavePlayer { loop { let mut last_one = false; - for mut out in out_buf.chunks_mut(8) { - for i in 0..160 { + for out in out_buf.chunks_mut(8) { + for i in in_buf.iter_mut() { let sample = match samples.next() { Some(Ok(sample)) => sample, _ => { @@ -192,16 +198,16 @@ impl WavePlayer { 0 } }; - in_buf[i] = sample; + *i = sample; } - codec.encode(&mut out, &in_buf); + codec.encode(out, &in_buf); } tx.transmit_stream_next(&StreamFrame { lich_idx: lsf_chunk as u8, lich_part: setup.lich_part(lsf_chunk as u8), frame_number, end_of_stream: last_one, - stream_data: out_buf.clone(), + stream_data: out_buf, }); frame_number += 1; lsf_chunk = (lsf_chunk + 1) % 6; diff --git a/m17core/src/kiss.rs b/m17core/src/kiss.rs index 4ada6dc..37d3d0b 100644 --- a/m17core/src/kiss.rs +++ b/m17core/src/kiss.rs @@ -543,7 +543,7 @@ mod tests { fn test_buffer_double() { let mut buffer = KissBuffer::new(); let buf = buffer.buf_remaining(); - buf[0..8].copy_from_slice(&[FEND, 0x10, 0x01, FEND, FEND, 0x20, 02, FEND]); + buf[0..8].copy_from_slice(&[FEND, 0x10, 0x01, FEND, FEND, 0x20, 0x02, FEND]); buffer.did_write(8); let next = buffer.next_frame().unwrap(); @@ -557,7 +557,7 @@ mod tests { fn test_buffer_double_shared_fend() { let mut buffer = KissBuffer::new(); let buf = buffer.buf_remaining(); - buf[0..7].copy_from_slice(&[FEND, 0x10, 0x01, FEND, 0x20, 02, FEND]); + buf[0..7].copy_from_slice(&[FEND, 0x10, 0x01, FEND, 0x20, 0x02, FEND]); buffer.did_write(7); let next = buffer.next_frame().unwrap(); @@ -571,7 +571,7 @@ mod tests { fn test_buffer_extra_fend() { let mut buffer = KissBuffer::new(); let buf = buffer.buf_remaining(); - buf[0..10].copy_from_slice(&[FEND, FEND, FEND, 0x10, 0x01, FEND, FEND, 0x20, 02, FEND]); + buf[0..10].copy_from_slice(&[FEND, FEND, FEND, 0x10, 0x01, FEND, FEND, 0x20, 0x02, FEND]); buffer.did_write(10); let next = buffer.next_frame().unwrap(); diff --git a/m17core/src/tnc.rs b/m17core/src/tnc.rs index a74499b..a64f367 100644 --- a/m17core/src/tnc.rs +++ b/m17core/src/tnc.rs @@ -502,6 +502,7 @@ struct OutgoingKiss { sent: usize, } +#[allow(clippy::large_enum_variant)] enum State { /// Nothing happening. We may have TX data queued but we won't act on it until CSMA opens up. Idle,