]> code.octet-stream.net Git - m17rt/commitdiff
Address more clippy lints
authorThomas Karpiniec <tom.karpiniec@outlook.com>
Mon, 27 Jan 2025 09:19:26 +0000 (20:19 +1100)
committerThomas Karpiniec <tom.karpiniec@outlook.com>
Mon, 27 Jan 2025 09:19:26 +0000 (20:19 +1100)
m17app/src/app.rs
m17app/src/soundcard.rs
m17app/src/soundmodem.rs
m17codec2/src/lib.rs
m17core/src/kiss.rs
m17core/src/tnc.rs

index 7d363dd1808522b986e06e687e39b82c3c8bd544..ae019768fe97876bf8960c25f0243e42186e1044 100644 (file)
@@ -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<T: Tnc>(mut tnc: T, adapters: Arc<RwLock<Adapters>>) {
         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<T: Tnc>(mut tnc: T, adapters: Arc<RwLock<Adapters>>) {
                         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<T: Tnc>(mut tnc: T, event_rx: mpsc::Receiver<TncControlEvent>) {
         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;
                     }
index b12ef8839a3d64f9be476e91ebae4ca63a941d39..391463208b5caaeb346a73b4e7c728710cff1a61 100644 (file)
@@ -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;
index 2d005b1b31b408f2134bd49ff5096659a4ffe876..974fd45085600b8fa60d1f7cac377e765415426d 100644 (file)
@@ -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<SoundmodemEvent>, buffer: Arc<RwLock<OutputBuffer>>);
     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<SoundmodemEvent>, buffer: Arc<RwLock<OutputBuffer>>) {
         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) {}
index 016acc78c49c2869ed0d58c78b2ac2705f5d7d62..1d05f2720f827ac23ed982c6f243b9b06486232e 100755 (executable)
@@ -61,6 +61,12 @@ impl Codec2Adapter {
     }
 }
 
+impl Default for Codec2Adapter {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 struct AdapterState {
     tx: Option<TxHandle>,
     /// 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;
index 4ada6dca77184ecad4508671a2de95b0b02c4deb..37d3d0ba31b57aa53c12f4f9de904ef4d3bf2278 100644 (file)
@@ -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();
index a74499b65112802caa2fbe9f497abe17ea530a74..a64f367e70c1f152eafb1892c311ee663b36ec35 100644 (file)
@@ -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,