Skip to content

Commit

Permalink
Update to Rust 2024 edition
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasHabets committed Feb 28, 2025
1 parent 4fcc61e commit b6d2367
Show file tree
Hide file tree
Showing 37 changed files with 58 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "rustradio"
version = "0.10.1"
edition = "2021"
edition = "2024"
license = "MIT"
authors = ["Thomas Habets <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion benches/bench_rustradio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions examples/ax25-1200-rx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -145,7 +145,7 @@ fn get_complex_input(

fn get_input(g: &mut Box<dyn GraphRunner>, opt: &Opt) -> Result<(ReadStream<Float>, 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,
Expand Down
2 changes: 1 addition & 1 deletion examples/bell202.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
14 changes: 8 additions & 6 deletions examples/circ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions examples/rtl_fm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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")]
{
Expand Down
2 changes: 1 addition & 1 deletion examples/sigmf.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_graph.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion examples/soapy_fm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion examples/tone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down
4 changes: 2 additions & 2 deletions src/audio_sink.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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};
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,
Expand Down
8 changes: 2 additions & 6 deletions src/binary_slicer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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 }
}
}
2 changes: 1 addition & 1 deletion src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/blocks.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/burst_tagger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -93,9 +93,9 @@ impl<T: Copy> BurstTagger<T> {
#[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();
Expand Down
6 changes: 3 additions & 3 deletions src/circular_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -516,8 +516,8 @@ impl<T: Copy> Buffer<T> {
#[cfg(test)]
mod tests {
use super::*;
use crate::stream::TagValue;
use crate::Float;
use crate::stream::TagValue;

#[test]
fn circ_reqlen() -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/constant_source.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
6 changes: 1 addition & 5 deletions src/correlate_access_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/debug_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 3 additions & 1 deletion src/file_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
6 changes: 1 addition & 5 deletions src/fir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/mtgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/null_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
5 changes: 3 additions & 2 deletions src/rational_resampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/rtlsdr_decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down
Loading

0 comments on commit b6d2367

Please sign in to comment.