From b6d2367ba5e7e6aec5b346f43828995f11e4e616 Mon Sep 17 00:00:00 2001 From: Thomas Habets Date: Fri, 28 Feb 2025 20:32:31 +0000 Subject: [PATCH] Update to Rust 2024 edition --- Cargo.toml | 2 +- benches/bench_rustradio.rs | 2 +- examples/ax25-1200-rx.rs | 6 +++--- examples/bell202.rs | 2 +- examples/circ.rs | 14 ++++++++------ examples/rtl_fm.rs | 6 ++++-- examples/sigmf.rs | 2 +- examples/simple_graph.rs | 2 +- examples/soapy_fm.rs | 2 +- examples/tone.rs | 2 +- src/add.rs | 2 +- src/audio_sink.rs | 4 ++-- src/binary_slicer.rs | 8 ++------ src/block.rs | 2 +- src/blocks.rs | 2 +- src/burst_tagger.rs | 4 ++-- src/circular_buffer.rs | 6 +++--- src/constant_source.rs | 2 +- src/correlate_access_code.rs | 6 +----- src/debug_sink.rs | 2 +- src/delay.rs | 2 +- src/file_sink.rs | 4 +++- src/fir.rs | 6 +----- src/graph.rs | 2 +- src/mtgraph.rs | 2 +- src/null_sink.rs | 2 +- src/rational_resampler.rs | 5 +++-- src/rtlsdr_decode.rs | 2 +- src/rtlsdr_source.rs | 2 +- src/single_pole_iir_filter.rs | 2 +- src/skip.rs | 2 +- src/symbol_sync.rs | 3 +-- src/to_text.rs | 2 +- src/vec_to_stream.rs | 2 +- src/vector_sink.rs | 2 +- src/vector_source.rs | 2 +- src/wpcr.rs | 6 +----- 37 files changed, 58 insertions(+), 68 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a5b0d6d..b2a4afe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rustradio" version = "0.10.1" -edition = "2021" +edition = "2024" license = "MIT" authors = ["Thomas Habets "] readme = "README.md" diff --git a/benches/bench_rustradio.rs b/benches/bench_rustradio.rs index 21dcdc8..0162bda 100644 --- a/benches/bench_rustradio.rs +++ b/benches/bench_rustradio.rs @@ -2,11 +2,11 @@ extern crate rustradio; extern crate test; +use rustradio::Complex; use rustradio::block::{Block, BlockRet}; use rustradio::blocks::*; use rustradio::stream::new_stream; use rustradio::window::WindowType; -use rustradio::Complex; use test::Bencher; diff --git a/examples/ax25-1200-rx.rs b/examples/ax25-1200-rx.rs index 1882f4e..5dd8ede 100644 --- a/examples/ax25-1200-rx.rs +++ b/examples/ax25-1200-rx.rs @@ -38,13 +38,13 @@ use std::path::PathBuf; use anyhow::Result; use clap::Parser; +use rustradio::Error; use rustradio::blocks::*; use rustradio::graph::GraphRunner; use rustradio::stream::ReadStream; use rustradio::window::WindowType; -use rustradio::Error; -use rustradio::{graph::Graph, mtgraph::MTGraph}; use rustradio::{Complex, Float}; +use rustradio::{graph::Graph, mtgraph::MTGraph}; #[derive(clap::Parser, Debug)] #[command(version, about)] @@ -145,7 +145,7 @@ fn get_complex_input( fn get_input(g: &mut Box, opt: &Opt) -> Result<(ReadStream, f32)> { if opt.audio { - if let Some(ref read) = &opt.read { + if let Some(read) = &opt.read { let prev = add_block![g, FileSource::new(read, false)?]; let prev = add_block![ g, diff --git a/examples/bell202.rs b/examples/bell202.rs index c5f10e7..4620af1 100644 --- a/examples/bell202.rs +++ b/examples/bell202.rs @@ -1,10 +1,10 @@ use anyhow::Result; use clap::Parser; +use rustradio::Complex; use rustradio::blocks::*; use rustradio::graph::Graph; use rustradio::graph::GraphRunner; -use rustradio::Complex; #[derive(clap::Parser, Debug)] #[command(version, about)] diff --git a/examples/circ.rs b/examples/circ.rs index 7eb00dc..22dfbd9 100644 --- a/examples/circ.rs +++ b/examples/circ.rs @@ -8,12 +8,14 @@ fn main() -> Result<()> { let b = Arc::new(Buffer::new(4096)?); let b2 = b.clone(); - std::thread::spawn(move || loop { - let (rb, _) = Arc::clone(&b2).read_buf().unwrap(); - println!("read buf: {:?}", rb.slice()); - let l = rb.slice().len(); - rb.consume(l); - std::thread::sleep(std::time::Duration::from_millis(1000)); + std::thread::spawn(move || { + loop { + let (rb, _) = Arc::clone(&b2).read_buf().unwrap(); + println!("read buf: {:?}", rb.slice()); + let l = rb.slice().len(); + rb.consume(l); + std::thread::sleep(std::time::Duration::from_millis(1000)); + } }); let mut n = 0; diff --git a/examples/rtl_fm.rs b/examples/rtl_fm.rs index 7bee5ce..a1f2fa4 100644 --- a/examples/rtl_fm.rs +++ b/examples/rtl_fm.rs @@ -164,8 +164,8 @@ fn render( use ratatui::layout::Constraint::Fill; use ratatui::layout::Layout; use ratatui::style::Color; - use ratatui::widgets::canvas::{Canvas, Line}; use ratatui::widgets::Block; + use ratatui::widgets::canvas::{Canvas, Line}; let [top, bottom] = Layout::vertical([Fill(1); 2]).areas(frame.area()); @@ -385,7 +385,9 @@ fn main() -> Result<()> { // Save to file. g.add(Box::new(FileSink::new(prev, out, Mode::Overwrite)?)); } else if !cfg!(feature = "audio") { - panic!("Rustradio build without feature 'audio'. Can only write to file with -o, not play live."); + panic!( + "Rustradio build without feature 'audio'. Can only write to file with -o, not play live." + ); } else { #[cfg(feature = "audio")] { diff --git a/examples/sigmf.rs b/examples/sigmf.rs index 1d9ef5e..ef73a93 100644 --- a/examples/sigmf.rs +++ b/examples/sigmf.rs @@ -1,10 +1,10 @@ use anyhow::Result; use clap::Parser; +use rustradio::Float; use rustradio::blocks::*; use rustradio::graph::Graph; use rustradio::graph::GraphRunner; -use rustradio::Float; #[derive(clap::Parser, Debug)] #[command(version, about)] diff --git a/examples/simple_graph.rs b/examples/simple_graph.rs index 5ee944d..7da5771 100644 --- a/examples/simple_graph.rs +++ b/examples/simple_graph.rs @@ -1,10 +1,10 @@ use anyhow::Result; use clap::Parser; +use rustradio::Complex; use rustradio::blocks::{AddConst, DebugSink, PduWriter, StreamToPdu, VectorSourceBuilder}; use rustradio::graph::Graph; use rustradio::graph::GraphRunner; -use rustradio::Complex; #[derive(clap::Parser, Debug)] #[command(version, about)] diff --git a/examples/soapy_fm.rs b/examples/soapy_fm.rs index b416058..5da12d7 100644 --- a/examples/soapy_fm.rs +++ b/examples/soapy_fm.rs @@ -7,11 +7,11 @@ mod internal { use clap::Parser; use log::warn; + use rustradio::Float; use rustradio::blocks::*; use rustradio::file_sink::Mode; use rustradio::graph::Graph; use rustradio::graph::GraphRunner; - use rustradio::Float; #[derive(clap::Parser, Debug)] #[command(version, about)] diff --git a/examples/tone.rs b/examples/tone.rs index e7ca977..c9c0316 100644 --- a/examples/tone.rs +++ b/examples/tone.rs @@ -5,10 +5,10 @@ use anyhow::Result; use clap::Parser; use log::warn; +use rustradio::Float; use rustradio::blocks::*; use rustradio::graph::Graph; use rustradio::graph::GraphRunner; -use rustradio::Float; #[derive(clap::Parser, Debug)] #[command(version, about)] diff --git a/src/add.rs b/src/add.rs index d854554..a7b23d8 100644 --- a/src/add.rs +++ b/src/add.rs @@ -66,9 +66,9 @@ where #[cfg(test)] mod tests { use super::*; + use crate::Float; use crate::block::Block; use crate::blocks::VectorSource; - use crate::Float; #[test] fn add_float() -> crate::Result<()> { diff --git a/src/audio_sink.rs b/src/audio_sink.rs index e39abf2..be7551f 100644 --- a/src/audio_sink.rs +++ b/src/audio_sink.rs @@ -1,6 +1,6 @@ use anyhow::Result; -use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; use cpal::Sample; +use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; use log::{debug, error, info, trace}; use crate::block::{Block, BlockRet}; @@ -8,7 +8,7 @@ use crate::graph::CancellationToken; use crate::stream::ReadStream; use crate::{Error, Float}; -use std::sync::mpsc::{sync_channel, SyncSender}; +use std::sync::mpsc::{SyncSender, sync_channel}; struct CpalOutput { device: cpal::Device, diff --git a/src/binary_slicer.rs b/src/binary_slicer.rs index 028c360..8afc367 100644 --- a/src/binary_slicer.rs +++ b/src/binary_slicer.rs @@ -3,8 +3,8 @@ //! TODO: should this be replaced with a MapBuilder, like in add_const? use anyhow::Result; -use crate::stream::{ReadStream, WriteStream}; use crate::Float; +use crate::stream::{ReadStream, WriteStream}; /// Turn positive Float values into binary `1u8`, and negative into `0u8`. #[derive(rustradio_macros::Block)] @@ -18,10 +18,6 @@ pub struct BinarySlicer { impl BinarySlicer { fn process_sync(&self, a: Float) -> u8 { - if a > 0.0 { - 1 - } else { - 0 - } + if a > 0.0 { 1 } else { 0 } } } diff --git a/src/block.rs b/src/block.rs index 14f015b..48cb388 100644 --- a/src/block.rs +++ b/src/block.rs @@ -7,8 +7,8 @@ thing, and you connect them together with streams to process the data. use anyhow::Result; -use crate::stream::StreamWait; use crate::Error; +use crate::stream::StreamWait; /** Return type for all blocks. diff --git a/src/blocks.rs b/src/blocks.rs index 6119a52..57361ee 100644 --- a/src/blocks.rs +++ b/src/blocks.rs @@ -1,6 +1,6 @@ //! Convenient mod collecting all standard library blocks for import. pub use crate::add::Add; -pub use crate::add_const::{add_const, AddConst}; +pub use crate::add_const::{AddConst, add_const}; pub use crate::au::{AuDecode, AuEncode}; pub use crate::binary_slicer::BinarySlicer; pub use crate::burst_tagger::BurstTagger; diff --git a/src/burst_tagger.rs b/src/burst_tagger.rs index f6c04b1..1b4d133 100644 --- a/src/burst_tagger.rs +++ b/src/burst_tagger.rs @@ -40,8 +40,8 @@ let pdus = StreamToPdu::new(burst_out, "burst".to_string(), 10_000, 50); use std::borrow::Cow; -use crate::stream::{ReadStream, Tag, TagValue, WriteStream}; use crate::Float; +use crate::stream::{ReadStream, Tag, TagValue, WriteStream}; /// Burst tagger: #[derive(rustradio_macros::Block)] @@ -93,9 +93,9 @@ impl BurstTagger { #[cfg(test)] mod tests { use super::*; + use crate::Result; use crate::block::Block; use crate::blocks::{VectorSink, VectorSource}; - use crate::Result; fn tag_compare(left: &[Tag], right: &[Tag]) { let mut left = left.to_vec(); diff --git a/src/circular_buffer.rs b/src/circular_buffer.rs index 6a69950..2203ca8 100644 --- a/src/circular_buffer.rs +++ b/src/circular_buffer.rs @@ -9,12 +9,12 @@ use std::os::fd::AsRawFd; use std::sync::{Arc, Condvar, Mutex}; use anyhow::Result; -use libc::{c_uchar, c_void, size_t}; use libc::{MAP_FAILED, MAP_FIXED, MAP_SHARED, PROT_READ, PROT_WRITE}; +use libc::{c_uchar, c_void, size_t}; use log::error; -use crate::stream::{Tag, TagPos}; use crate::Error; +use crate::stream::{Tag, TagPos}; #[derive(Debug)] struct Map { @@ -516,8 +516,8 @@ impl Buffer { #[cfg(test)] mod tests { use super::*; - use crate::stream::TagValue; use crate::Float; + use crate::stream::TagValue; #[test] fn circ_reqlen() -> Result<()> { diff --git a/src/constant_source.rs b/src/constant_source.rs index 6a12ebc..649a42b 100644 --- a/src/constant_source.rs +++ b/src/constant_source.rs @@ -1,9 +1,9 @@ //! Generate the same value, forever. use anyhow::Result; +use crate::Error; use crate::block::{Block, BlockRet}; use crate::stream::WriteStream; -use crate::Error; /// Generate the same value, forever. #[derive(rustradio_macros::Block)] diff --git a/src/correlate_access_code.rs b/src/correlate_access_code.rs index ea3ea70..5b6141f 100644 --- a/src/correlate_access_code.rs +++ b/src/correlate_access_code.rs @@ -45,11 +45,7 @@ impl CorrelateAccessCode { .zip(&self.code) .filter(|(a, b)| a != b) .count(); - if diffs <= self.allowed_diffs { - 1 - } else { - 0 - } + if diffs <= self.allowed_diffs { 1 } else { 0 } } } diff --git a/src/debug_sink.rs b/src/debug_sink.rs index 2ddd313..8cf8435 100644 --- a/src/debug_sink.rs +++ b/src/debug_sink.rs @@ -3,9 +3,9 @@ use std::collections::HashMap; use anyhow::Result; +use crate::Error; use crate::block::{Block, BlockRet}; use crate::stream::{NCReadStream, NCWriteStream, ReadStream, Tag, TagPos}; -use crate::Error; /// Nocopy version of DebugSink. // TODO: maybe merge with DebugSink using an enum? diff --git a/src/delay.rs b/src/delay.rs index 46cbb1e..551650c 100644 --- a/src/delay.rs +++ b/src/delay.rs @@ -2,9 +2,9 @@ use anyhow::Result; use log::debug; +use crate::Error; use crate::block::{Block, BlockRet}; use crate::stream::{ReadStream, WriteStream}; -use crate::Error; /// Delay stream. Good for syncing up streams. #[derive(rustradio_macros::Block)] diff --git a/src/file_sink.rs b/src/file_sink.rs index f6bc6d4..12a20c2 100644 --- a/src/file_sink.rs +++ b/src/file_sink.rs @@ -148,7 +148,9 @@ mod tests { let out = std::fs::read(tmpfn)?; assert_eq!( out, - vec![0, 0, 128, 63, 0, 0, 64, 64, 195, 245, 72, 64, 195, 245, 72, 192] + vec![ + 0, 0, 128, 63, 0, 0, 64, 64, 195, 245, 72, 64, 195, 245, 72, 192 + ] ); Ok(()) } diff --git a/src/fir.rs b/src/fir.rs index 7f915ba..24da8c1 100644 --- a/src/fir.rs +++ b/src/fir.rs @@ -242,11 +242,7 @@ pub fn low_pass_complex( fn compute_ntaps(samp_rate: Float, twidth: Float, window_type: &WindowType) -> usize { let a = window_type.max_attenuation(); let t = (a * samp_rate / (22.0 * twidth)) as usize; - if (t & 1) == 0 { - t + 1 - } else { - t - } + if (t & 1) == 0 { t + 1 } else { t } } /// Create taps for a low pass filter. diff --git a/src/graph.rs b/src/graph.rs index 001288d..52feb98 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -90,7 +90,7 @@ impl Graph { #[must_use] pub(crate) fn get_cpu_time() -> std::time::Duration { - use libc::{clock_gettime, timespec, CLOCK_PROCESS_CPUTIME_ID}; + use libc::{CLOCK_PROCESS_CPUTIME_ID, clock_gettime, timespec}; // SAFETY: Zeroing out a timespec struct is just all zeroes. let mut ts: timespec = unsafe { std::mem::zeroed() }; // SAFETY: Local variable written my C function. diff --git a/src/mtgraph.rs b/src/mtgraph.rs index 7e78997..5d0c692 100644 --- a/src/mtgraph.rs +++ b/src/mtgraph.rs @@ -7,7 +7,7 @@ use anyhow::Result; use log::{debug, error, info}; use crate::block::{Block, BlockRet}; -use crate::graph::{get_cpu_time, CancellationToken}; +use crate::graph::{CancellationToken, get_cpu_time}; #[derive(Default, Debug)] struct BlockStats { diff --git a/src/null_sink.rs b/src/null_sink.rs index 7641481..a286ab7 100644 --- a/src/null_sink.rs +++ b/src/null_sink.rs @@ -2,9 +2,9 @@ use anyhow::Result; +use crate::Error; use crate::block::{Block, BlockRet}; use crate::stream::ReadStream; -use crate::Error; /// Discard anything written to this block. #[derive(rustradio_macros::Block)] diff --git a/src/rational_resampler.rs b/src/rational_resampler.rs index 6bb7a18..a9e562c 100644 --- a/src/rational_resampler.rs +++ b/src/rational_resampler.rs @@ -5,9 +5,9 @@ use anyhow::Result; use log::trace; +use crate::Error; use crate::block::{Block, BlockRet}; use crate::stream::{ReadStream, WriteStream}; -use crate::Error; fn gcd(mut a: usize, mut b: usize) -> usize { while b != 0 { @@ -119,7 +119,8 @@ mod tests { finalcount, res.len(), "inputsize={inputsize} interp={interp} deci={deci} finalcount={finalcount}: Actual={} values={:?}", - res.len(), res.slice() + res.len(), + res.slice() ); Ok(()) } diff --git a/src/rtlsdr_decode.rs b/src/rtlsdr_decode.rs index 8de500a..6517621 100644 --- a/src/rtlsdr_decode.rs +++ b/src/rtlsdr_decode.rs @@ -47,8 +47,8 @@ impl Block for RtlSdrDecode { #[cfg(test)] mod tests { use super::*; - use crate::blocks::VectorSource; use crate::Complex; + use crate::blocks::VectorSource; #[test] fn empty() -> crate::Result<()> { diff --git a/src/rtlsdr_source.rs b/src/rtlsdr_source.rs index 2b65fa7..515e742 100644 --- a/src/rtlsdr_source.rs +++ b/src/rtlsdr_source.rs @@ -18,9 +18,9 @@ use std::thread; use anyhow::Result; use log::{debug, warn}; +use crate::Error; use crate::block::{Block, BlockRet}; use crate::stream::{ReadStream, WriteStream}; -use crate::Error; const CHUNK_SIZE: usize = 8192; const MAX_CHUNKS_IN_FLIGHT: usize = 1000; diff --git a/src/single_pole_iir_filter.rs b/src/single_pole_iir_filter.rs index 09eb90a..bf4b119 100644 --- a/src/single_pole_iir_filter.rs +++ b/src/single_pole_iir_filter.rs @@ -1,8 +1,8 @@ //! Infinite Impulse Response (IIR) filter. use anyhow::Result; -use crate::stream::{ReadStream, WriteStream}; use crate::Float; +use crate::stream::{ReadStream, WriteStream}; struct SinglePoleIIR { alpha: Float, // TODO: GNURadio uses double diff --git a/src/skip.rs b/src/skip.rs index e32d81b..4f9da7d 100644 --- a/src/skip.rs +++ b/src/skip.rs @@ -1,9 +1,9 @@ //! Skip samples, then stream at full speed. use anyhow::Result; +use crate::Error; use crate::block::{Block, BlockRet}; use crate::stream::{ReadStream, WriteStream}; -use crate::Error; /// Turn samples into text. #[derive(rustradio_macros::Block)] diff --git a/src/symbol_sync.rs b/src/symbol_sync.rs index 9b72945..e551b25 100644 --- a/src/symbol_sync.rs +++ b/src/symbol_sync.rs @@ -180,8 +180,7 @@ impl Block for SymbolSync { } trace!( "SymbolSync: clock@{} pre={pre} now={t} min={mi} max={mx} => {}", - self.stream_pos, - self.clock + self.stream_pos, self.clock ); } } diff --git a/src/to_text.rs b/src/to_text.rs index 330c73d..71b0d6c 100644 --- a/src/to_text.rs +++ b/src/to_text.rs @@ -22,9 +22,9 @@ g.add(Box::new(sink)); */ use anyhow::Result; +use crate::Error; use crate::block::{Block, BlockRet}; use crate::stream::{ReadStream, WriteStream}; -use crate::Error; /// Turn samples into text. /// diff --git a/src/vec_to_stream.rs b/src/vec_to_stream.rs index e7f6661..353f178 100644 --- a/src/vec_to_stream.rs +++ b/src/vec_to_stream.rs @@ -2,9 +2,9 @@ Turn stream of e.g. `Vec` to stream of `u8`. */ +use crate::Error; use crate::block::{Block, BlockRet}; use crate::stream::{NCReadStream, ReadStream, WriteStream}; -use crate::Error; /// Block for vector to stream. #[derive(rustradio_macros::Block)] diff --git a/src/vector_sink.rs b/src/vector_sink.rs index c5fdb83..60cd58a 100644 --- a/src/vector_sink.rs +++ b/src/vector_sink.rs @@ -3,9 +3,9 @@ //! This block is really only useful for unit tests. use anyhow::Result; +use crate::Error; use crate::block::{Block, BlockRet}; use crate::stream::{ReadStream, Tag}; -use crate::Error; /// VectorSink. #[derive(rustradio_macros::Block)] diff --git a/src/vector_source.rs b/src/vector_source.rs index 8d1f68e..f6bffd7 100644 --- a/src/vector_source.rs +++ b/src/vector_source.rs @@ -1,9 +1,9 @@ //! Generate values from a fixed vector. use anyhow::Result; +use crate::Error; use crate::block::{Block, BlockRet}; use crate::stream::{ReadStream, Tag, TagValue, WriteStream}; -use crate::Error; /// Repeat or counts. pub enum Repeat { diff --git a/src/wpcr.rs b/src/wpcr.rs index 1e721eb..631acfa 100644 --- a/src/wpcr.rs +++ b/src/wpcr.rs @@ -173,11 +173,7 @@ impl Wpcr { let samples_per_symbol = bin as Float / samples.len() as Float; let mut clock_phase = { let t = 0.5 + d[bin].arg() / (std::f64::consts::PI * 2.0) as Float; - if t > 0.5 { - t - } else { - t + 1.0 - } + if t > 0.5 { t } else { t + 1.0 } }; debug!("WPCR: sps: {}", samples_per_symbol); if let Some(samp_rate) = self.samp_rate {