Skip to content

Commit b0a6b97

Browse files
style: format, migrate to 2024 Edition, and fix remaining clippy lints (#31)
* style: run (patched) rustfmt I was originally perplexed as to why the crate wasn't already formatted, but quickly found out why... Though the PR seems to have languished for some time, I've run a patched version of rustfmt that completes without crashing: rust-lang/rustfmt#6396 * style: fix `mismatched_lifetime_syntaxes` lint * style: remove unnecessary macro imports This is a strange case — I had to look this up myself! Because you have a `#[macro_use]` above the `params` module in `lib.rs`, all of the macros in `params.rs` are automatically made available crate-wide. This import of the macro in `scan_properties.rs` is therefore redundant! The same logic applies to `impl_param_described`. https://lukaswirth.dev/tlborm/decl-macros/minutiae/scoping.html * style: fix clippy `derivable_impls` For `enum`s, you can add a tag and `#[derive(Default)]` instead of manually implementing the same code: https://doc.rust-lang.org/std/default/trait.Default.html#enums * style: fix clippy `single_match` * style: fix clippy `redundant_closure` * style: clippy fix `unnecessary_unwrap` * style: clippy fix `manual_is_multiple_of` NOTE: This method was added in a recent version of Rust (1.87.0), so changing to this code means that our minimum supported Rust version would become that! If you'd rather keep compatibility with older-than-stable versions of Rust, we should leave this unchanged! * chore(edition): run `cargo update` * style(edition): run `cargo --fix edition` Performs some automatic migration to the 2024 edition of Rust. Will be followed by a cleanup commit. * style(edition): bump to Rust 2024 * style(edition): reformat using (patched) rustfmt This is now a different, newer PR that supports the 2024 edition: rust-lang/rustfmt#6630 * style(edition): `expr_2021` -> `expr` in macros The 2024 edition changed `expr`s to accept `const` and `_` expressions, but because no macros in `mzdata` included any `const` or `_` keywords in their syntax, no change needs to be made. * style(edition): `match` back to `if let` None of the migrated code seemed to depend on any exact `Drop` timing, so the overly-cautious `if let` -> `match` migration was unnecessary. * style(edition): change `gen` to `this_generation` In the 2024 edition, `gen` became a reserved Rust keyword. Using `r#gen` is still possible, but probably not best practice, so I've renamed the old `gen` variables. * style: fix clippy `let_and_return` * style: fix clippy `collapsible_if`
1 parent 2dc3cf6 commit b0a6b97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3448
-2602
lines changed

Cargo.lock

Lines changed: 472 additions & 412 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "mzdata"
33
version = "0.59.3"
4-
edition = "2021"
4+
edition = "2024"
55
keywords = ['mass-spectrometry', 'mzml', 'mgf']
66

77
categories = ["science", "parser-implementations", "data-structures"]

benches/mzml.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use criterion::{black_box, criterion_group, criterion_main, Criterion};
1+
use criterion::{Criterion, black_box, criterion_group, criterion_main};
22

33
use std::fs;
44

examples/async_mzcat.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ async fn scan_file(reader: &mut mzml::AsyncMzMLReader<fs::File>) {
4848
#[tokio::main(flavor = "multi_thread", worker_threads = 10)]
4949
async fn main() -> io::Result<()> {
5050
let path = path::PathBuf::from(
51-
env::args().nth(1)
51+
env::args()
52+
.nth(1)
5253
.expect("Please pass an MS data file path"),
5354
);
5455
if let Some(ext) = path.extension() {

examples/from_stdin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::io::{self, Seek};
55
use std::time::Instant;
66

77
use mzdata::io::{
8-
infer_from_stream, MassSpectrometryFormat, PreBufferedStream, RestartableGzDecoder,
9-
SpectrumSource,
8+
MassSpectrometryFormat, PreBufferedStream, RestartableGzDecoder, SpectrumSource,
9+
infer_from_stream,
1010
};
1111
use mzdata::{MGFReader, MzMLReader};
1212

examples/get_scan_by.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,16 @@ fn main() -> io::Result<()> {
3434
};
3535

3636
// dbg!(spectrum);
37-
println!("ID: {}; Index: {}; Time: {}", spectrum.id(), spectrum.index(), spectrum.start_time());
38-
println!("Num data points: {}", spectrum.raw_arrays().unwrap().mzs().unwrap().len());
37+
println!(
38+
"ID: {}; Index: {}; Time: {}",
39+
spectrum.id(),
40+
spectrum.index(),
41+
spectrum.start_time()
42+
);
43+
println!(
44+
"Num data points: {}",
45+
spectrum.raw_arrays().unwrap().mzs().unwrap().len()
46+
);
3947

4048
Ok(())
4149
}

examples/infer_format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::env;
66
use std::io;
77
use std::process::exit;
88

9-
use mzdata::io::{infer_format, infer_from_stream, PreBufferedStream};
9+
use mzdata::io::{PreBufferedStream, infer_format, infer_from_stream};
1010

1111
fn main() -> io::Result<()> {
1212
let input = env::args().nth(1).unwrap_or_else(|| {

examples/mzcat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::time;
22
use std::{env, io, path};
33

44
use mzdata::spectrum::MultiLayerSpectrum;
5-
use mzdata::{prelude::*, MZReader};
5+
use mzdata::{MZReader, prelude::*};
66
use rayon::prelude::*;
77

88
fn scan_file<R: MZFileReader + Iterator<Item = MultiLayerSpectrum> + Send>(reader: &mut R) {

examples/mzconvert.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,31 @@ use std::any::Any;
22
use std::fs::File;
33
use std::io;
44
use std::path::PathBuf;
5-
use std::sync::{mpsc::sync_channel, Arc, atomic::{AtomicU64, Ordering as AtomicOrdering}};
5+
use std::sync::{
6+
Arc,
7+
atomic::{AtomicU64, Ordering as AtomicOrdering},
8+
mpsc::sync_channel,
9+
};
610
use std::thread;
711
use std::time;
812

913
use clap::Parser;
1014

1115
use log::info;
1216
use mzdata::io::MassSpectrometryFormat;
13-
use mzdata::io::{checksum_file, MassSpectrometryReadWriteProcess, Sink, Source};
14-
use mzdata::meta::custom_software_name;
17+
use mzdata::io::{MassSpectrometryReadWriteProcess, Sink, Source, checksum_file};
1518
use mzdata::meta::Software;
19+
use mzdata::meta::custom_software_name;
1620
use mzdata::meta::{DataProcessing, ProcessingMethod, SourceFile};
1721
use mzdata::params::ControlledVocabulary;
1822
use mzdata::prelude::*;
1923

20-
use mzdata::spectrum::bindata::BinaryCompressionType;
24+
use mzdata::MzMLWriter;
2125
use mzdata::spectrum::ArrayType;
2226
use mzdata::spectrum::ArrayType::IntensityArray;
2327
use mzdata::spectrum::ArrayType::MZArray;
2428
use mzdata::spectrum::BinaryDataArrayType;
25-
use mzdata::MzMLWriter;
29+
use mzdata::spectrum::bindata::BinaryCompressionType;
2630
use mzpeaks::{CentroidPeak, DeconvolutedPeak};
2731

2832
fn compression_parser(compression: &str) -> Result<BinaryCompressionType, String> {
@@ -32,9 +36,11 @@ fn compression_parser(compression: &str) -> Result<BinaryCompressionType, String
3236
compression.to_string()
3337
};
3438

35-
BinaryCompressionType::COMPRESSION_METHODS.iter().find(|x| {
36-
x.as_param().unwrap().name() == compression
37-
}).copied().ok_or_else(|| compression.to_string())
39+
BinaryCompressionType::COMPRESSION_METHODS
40+
.iter()
41+
.find(|x| x.as_param().unwrap().name() == compression)
42+
.copied()
43+
.ok_or_else(|| compression.to_string())
3844
}
3945

4046
#[derive(Debug, Clone, Parser)]
@@ -44,7 +50,7 @@ pub struct MZConvert {
4450
#[arg()]
4551
pub outpath: String,
4652

47-
#[arg(short='b', long, default_value_t=8192)]
53+
#[arg(short = 'b', long, default_value_t = 8192)]
4854
pub buffer_size: usize,
4955

5056
#[arg(long, value_parser=compression_parser, default_value="zlib compression")]
@@ -91,7 +97,7 @@ impl MZConvert {
9197
mut writer: W,
9298
) -> io::Result<()> {
9399
let (send, recv) = sync_channel(self.buffer_size);
94-
let buffered= Arc::new(AtomicU64::default());
100+
let buffered = Arc::new(AtomicU64::default());
95101
let buffered_w = Arc::clone(&buffered);
96102
let reader_handle = thread::spawn(move || {
97103
reader.enumerate().for_each(|(i, s)| {
@@ -111,9 +117,10 @@ impl MZConvert {
111117
for s in recv.iter() {
112118
let i = s.index();
113119
buffered_w.fetch_sub(1, AtomicOrdering::SeqCst);
114-
writer.write_owned(s).inspect_err(|e| {
115-
log::error!("Failed to write spectrum {i}: {e}")
116-
}).unwrap();
120+
writer
121+
.write_owned(s)
122+
.inspect_err(|e| log::error!("Failed to write spectrum {i}: {e}"))
123+
.unwrap();
117124
}
118125
writer.close().unwrap();
119126
});
@@ -190,7 +197,6 @@ impl MZConvert {
190197
self.ion_mobility_compression,
191198
);
192199
}
193-
194200
}
195201
}
196202
}
@@ -251,7 +257,7 @@ impl MassSpectrometryReadWriteProcess<CentroidPeak, DeconvolutedPeak> for MZConv
251257
Default::default()
252258
} else {
253259
info!("Computing checksum for {}", pb.display());
254-
260+
255261
checksum_file(&pb)?
256262
};
257263
let has_already = reader

examples/mzinfo.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ use std::time;
88

99
use std::sync::mpsc::sync_channel;
1010

11+
use mzdata::MZReader;
1112
use mzdata::io::Source;
1213
use mzdata::prelude::*;
1314
use mzdata::spectrum::{
1415
DeconvolutedSpectrum, MultiLayerSpectrum, RefPeakDataLevel, SignalContinuity, SpectrumLike,
1516
};
16-
use mzdata::MZReader;
1717

1818
struct MSDataFileSummary {
1919
pub start_time: f64,
@@ -22,7 +22,7 @@ struct MSDataFileSummary {
2222
pub charge_table: HashMap<i32, usize>,
2323
pub peak_charge_table: HashMap<u8, HashMap<i32, usize>>,
2424
pub peak_mode_table: HashMap<SignalContinuity, usize>,
25-
pub has_ion_mobility: bool
25+
pub has_ion_mobility: bool,
2626
}
2727

2828
impl Default for MSDataFileSummary {
@@ -112,11 +112,10 @@ impl MSDataFileSummary {
112112
let start = time::Instant::now();
113113
let (sender, receiver) = sync_channel(2usize.pow(12));
114114
let read_handle = spawn(move || {
115-
reader.into_iter()
115+
reader
116+
.into_iter()
116117
.enumerate()
117-
.for_each(|(i, scan)| {
118-
sender.send((i, scan)).unwrap()
119-
});
118+
.for_each(|(i, scan)| sender.send((i, scan)).unwrap());
120119
});
121120
let i = receiver.iter().fold(0, |_, (i, scan)| {
122121
if i % 10000 == 0 && i > 0 {
@@ -134,7 +133,10 @@ impl MSDataFileSummary {
134133
read_handle.join().unwrap();
135134
let end = time::Instant::now();
136135
let elapsed = end - start;
137-
println!("{:0.3} seconds elapsed, handled {i} spectra", elapsed.as_secs_f64());
136+
println!(
137+
"{:0.3} seconds elapsed, handled {i} spectra",
138+
elapsed.as_secs_f64()
139+
);
138140
}
139141

140142
pub fn write_out(&self) {

0 commit comments

Comments
 (0)