Skip to content

Commit 2e56f98

Browse files
committed
chore(edition): move to Rust 2024 edition
1 parent 52fded4 commit 2e56f98

32 files changed

+459
-480
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "pgfinder-next"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55

66
[workspace]
77
members = [

crates/dimer-builder/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "dimer-builder"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55

66
[dependencies]
77
muropeptide = { path = "../muropeptide" }

crates/muropeptide/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "muropeptide"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55

66
[dependencies]
77
itertools = "0.13.0"

crates/muropeptide/benches/api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use divan::AllocProfiler;
22
use once_cell::sync::Lazy;
3-
use polychem::{atoms::atomic_database, AtomicDatabase, PolymerDatabase, Polymerizer};
3+
use polychem::{AtomicDatabase, PolymerDatabase, Polymerizer, atoms::atomic_database};
44

55
#[global_allocator]
66
static ALLOC: AllocProfiler = AllocProfiler::system();

crates/muropeptide/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ use std::fmt::{self, Display, Formatter};
55

66
use itertools::Itertools;
77
use miette::Diagnostic;
8-
use nom_miette::{final_parser, LabeledError};
8+
use nom_miette::{LabeledError, final_parser};
99
use once_cell::sync::Lazy;
10-
use parser::{muropeptide, MuropeptideErrorKind};
10+
use parser::{MuropeptideErrorKind, muropeptide};
1111
// FIXME: Blocks need separating and reordering!
1212
use polychem::{
13-
errors::PolychemError, AtomicDatabase, AverageMass, BondId, Charged, GroupState, Massive,
14-
ModificationInfo, MonoisotopicMass, Polymer, PolymerDatabase, Polymerizer, ResidueId,
13+
AtomicDatabase, AverageMass, BondId, Charged, GroupState, Massive, ModificationInfo,
14+
MonoisotopicMass, Polymer, PolymerDatabase, Polymerizer, ResidueId, errors::PolychemError,
1515
};
1616
use smithereens::Dissociable;
1717
use thiserror::Error;

crates/muropeptide/src/parser.rs

+26-36
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ use std::{cell::RefCell, iter::zip};
33
use itertools::{EitherOrBoth, Itertools};
44
use miette::Diagnostic;
55
use nom::{
6+
IResult,
67
branch::alt,
78
bytes::complete::tag,
89
character::complete::{alpha1, alphanumeric1, char, one_of, space0, space1},
910
combinator::{cut, map, opt, recognize},
1011
error::ErrorKind,
1112
multi::{many0, many1, separated_list1},
1213
sequence::{delimited, pair, preceded, terminated, tuple},
13-
IResult,
1414
};
15-
use nom_miette::{map_res, wrap_err, FromExternalError, LabeledErrorKind, LabeledParseError};
15+
use nom_miette::{FromExternalError, LabeledErrorKind, LabeledParseError, map_res, wrap_err};
1616
use polychem::{
17+
Count, ModificationId, Polymer, Polymerizer,
1718
errors::PolychemError,
1819
parsers::{
1920
chemical_composition,
2021
errors::PolychemErrorKind,
2122
primitives::{count, lowercase, offset_kind, uppercase},
2223
},
23-
Count, ModificationId, Polymer, Polymerizer,
2424
};
2525
use thiserror::Error;
2626

@@ -38,13 +38,6 @@ const CTON_BOND: &str = "CToN";
3838
const CROSSLINK_BOND: &str = "Link";
3939
const LAT_CROSSLINK_BOND: &str = "Lat-Link";
4040

41-
// FIXME: A horrible hack that's needed to specify the lifetimes captured by `impl FnMut(...) -> ...` correctly. Once
42-
// Rust 2024 is stabilized, however, this hack can be removed. Keep an eye on:
43-
// https://github.com/rust-lang/rust/issues/117587
44-
// FIXME: Make private again
45-
pub trait Captures<U> {}
46-
impl<T: ?Sized, U> Captures<U> for T {}
47-
4841
// FIXME: Paste all of these EBNF comments into another file and make sure they are valid!
4942

5043
/// Muropeptide = Monomer , { Connection , Monomer } , [ Connection ] , [ { " " }- ,
@@ -57,8 +50,7 @@ impl<T: ?Sized, U> Captures<U> for T {}
5750
#[allow(clippy::too_many_lines)]
5851
pub fn muropeptide<'z, 'a, 'p, 's>(
5952
polymerizer: &'z Polymerizer<'a, 'p>,
60-
) -> impl FnMut(&'s str) -> ParseResult<'s, Muropeptide<'a, 'p>> + Captures<(&'z (), &'a (), &'p ())>
61-
{
53+
) -> impl FnMut(&'s str) -> ParseResult<'s, Muropeptide<'a, 'p>> {
6254
move |i| {
6355
let polymer = RefCell::new(polymerizer.new_polymer());
6456
// FIXME: Perhaps there is a better way to shorten that `polymer` borrow...
@@ -208,22 +200,19 @@ pub fn muropeptide<'z, 'a, 'p, 's>(
208200
};
209201

210202
let polymer = polymer.into_inner();
211-
Ok((
212-
rest,
213-
Muropeptide {
214-
polymer,
215-
monomers,
216-
connections,
217-
},
218-
))
203+
Ok((rest, Muropeptide {
204+
polymer,
205+
monomers,
206+
connections,
207+
}))
219208
}
220209
}
221210

222211
/// Monomer = Glycan , [ "-" , Peptide ] | Peptide ;
223212
// FIXME: Make private again
224213
pub fn monomer<'c, 'a, 'p, 's>(
225214
polymer: &'c RefCell<Polymer<'a, 'p>>,
226-
) -> impl FnMut(&'s str) -> ParseResult<'s, Monomer> + Captures<(&'c (), &'a (), &'p ())> {
215+
) -> impl FnMut(&'s str) -> ParseResult<'s, Monomer> {
227216
let optional_peptide = opt(preceded(char('-'), cut(peptide(polymer))));
228217
let glycan_and_peptide = map_res(
229218
pair(glycan(polymer), optional_peptide),
@@ -261,8 +250,7 @@ pub fn monomer<'c, 'a, 'p, 's>(
261250
/// Glycan = { Monosaccharide }- ;
262251
fn glycan<'c, 'a, 'p, 's>(
263252
polymer: &'c RefCell<Polymer<'a, 'p>>,
264-
) -> impl FnMut(&'s str) -> ParseResult<'s, Vec<Monosaccharide>> + Captures<(&'c (), &'a (), &'p ())>
265-
{
253+
) -> impl FnMut(&'s str) -> ParseResult<'s, Vec<Monosaccharide>> {
266254
let parser = many1(monosaccharide(polymer));
267255
map_res(parser, |residues| {
268256
polymer
@@ -275,7 +263,7 @@ fn glycan<'c, 'a, 'p, 's>(
275263
/// Peptide = { Amino Acid }- ;
276264
fn peptide<'c, 'a, 'p, 's>(
277265
polymer: &'c RefCell<Polymer<'a, 'p>>,
278-
) -> impl FnMut(&'s str) -> ParseResult<'s, Vec<AminoAcid>> + Captures<(&'c (), &'a (), &'p ())> {
266+
) -> impl FnMut(&'s str) -> ParseResult<'s, Vec<AminoAcid>> {
279267
let parser = many1(amino_acid(polymer));
280268
map_res(parser, |residues| {
281269
let residue_ids = residues.iter().map(|aa| aa.residue);
@@ -289,7 +277,7 @@ fn peptide<'c, 'a, 'p, 's>(
289277
/// Monosaccharide = lowercase , [ Modifications ] ;
290278
fn monosaccharide<'c, 'a, 'p, 's>(
291279
polymer: &'c RefCell<Polymer<'a, 'p>>,
292-
) -> impl FnMut(&'s str) -> ParseResult<'s, Monosaccharide> + Captures<(&'c (), &'a (), &'p ())> {
280+
) -> impl FnMut(&'s str) -> ParseResult<'s, Monosaccharide> {
293281
let parser = pair(recognize(lowercase), opt(modifications(polymer)));
294282
map_res(parser, |(abbr, modifications)| {
295283
let residue = polymer.borrow_mut().new_residue(abbr)?;
@@ -307,7 +295,7 @@ fn monosaccharide<'c, 'a, 'p, 's>(
307295
/// Amino Acid = Unbranched Amino Acid , [ Lateral Chain ] ;
308296
fn amino_acid<'c, 'a, 'p, 's>(
309297
polymer: &'c RefCell<Polymer<'a, 'p>>,
310-
) -> impl FnMut(&'s str) -> ParseResult<'s, AminoAcid> + Captures<(&'c (), &'a (), &'p ())> {
298+
) -> impl FnMut(&'s str) -> ParseResult<'s, AminoAcid> {
311299
let parser = pair(unbranched_amino_acid(polymer), opt(lateral_chain(polymer)));
312300
map_res(parser, |(residue, lateral_chain)| {
313301
if let Some(LateralChain { direction, peptide }) = &lateral_chain {
@@ -351,8 +339,7 @@ fn amino_acid<'c, 'a, 'p, 's>(
351339
/// { { " " } , "," , { " " } , Any Modification } , ")" ;
352340
fn modifications<'c, 'a, 'p, 's>(
353341
polymer: &'c RefCell<Polymer<'a, 'p>>,
354-
) -> impl FnMut(&'s str) -> ParseResult<'s, Vec<ModificationId>> + Captures<(&'c (), &'a (), &'p ())>
355-
{
342+
) -> impl FnMut(&'s str) -> ParseResult<'s, Vec<ModificationId>> {
356343
let separator = delimited(space0, char(','), space0);
357344
delimited(
358345
char('('),
@@ -364,8 +351,7 @@ fn modifications<'c, 'a, 'p, 's>(
364351
/// Unbranched Amino Acid = [ lowercase ] , uppercase , [ Modifications ] ;
365352
fn unbranched_amino_acid<'c, 'a, 'p, 's>(
366353
polymer: &'c RefCell<Polymer<'a, 'p>>,
367-
) -> impl FnMut(&'s str) -> ParseResult<'s, UnbranchedAminoAcid> + Captures<(&'c (), &'a (), &'p ())>
368-
{
354+
) -> impl FnMut(&'s str) -> ParseResult<'s, UnbranchedAminoAcid> {
369355
let abbr = recognize(preceded(opt(lowercase), uppercase));
370356
let parser = pair(abbr, opt(modifications(polymer)));
371357
map_res(parser, |(abbr, modifications)| {
@@ -385,7 +371,7 @@ fn unbranched_amino_acid<'c, 'a, 'p, 's>(
385371
/// Lateral Chain = "[" , Peptide Direction , { Unbranched Amino Acid }- , "]" ;
386372
fn lateral_chain<'c, 'a, 'p, 's>(
387373
polymer: &'c RefCell<Polymer<'a, 'p>>,
388-
) -> impl FnMut(&'s str) -> ParseResult<'s, LateralChain> + Captures<(&'c (), &'a (), &'p ())> {
374+
) -> impl FnMut(&'s str) -> ParseResult<'s, LateralChain> {
389375
let peptide = many1(unbranched_amino_acid(polymer));
390376
let parser = delimited(char('['), peptide, char(']'));
391377
map(parser, |peptide| LateralChain {
@@ -417,15 +403,15 @@ fn identifier(i: &str) -> ParseResult<&str> {
417403
/// Any Modification = Named Modification | Offset Modification
418404
pub fn any_modification<'c, 'a, 'p, 's>(
419405
polymer: &'c RefCell<Polymer<'a, 'p>>,
420-
) -> impl FnMut(&'s str) -> ParseResult<'s, ModificationId> + Captures<(&'c (), &'a (), &'p ())> {
406+
) -> impl FnMut(&'s str) -> ParseResult<'s, ModificationId> {
421407
alt((named_modification(polymer), offset_modification(polymer)))
422408
}
423409

424410
// FIXME: I probably need to add a lot of `wrap_err`s around these parsers!
425411
/// Named Modification = [ Multiplier ] , Identifier
426412
pub fn named_modification<'c, 'a, 'p, 's>(
427413
polymer: &'c RefCell<Polymer<'a, 'p>>,
428-
) -> impl FnMut(&'s str) -> ParseResult<'s, ModificationId> + Captures<(&'c (), &'a (), &'p ())> {
414+
) -> impl FnMut(&'s str) -> ParseResult<'s, ModificationId> {
429415
let parser = pair(opt(multiplier), identifier);
430416
map_res(parser, |(multiplier, named_mod)| {
431417
polymer
@@ -439,7 +425,7 @@ pub fn named_modification<'c, 'a, 'p, 's>(
439425
/// Chemical Composition ;
440426
pub fn offset_modification<'c, 'a, 'p, 's>(
441427
polymer: &'c RefCell<Polymer<'a, 'p>>,
442-
) -> impl FnMut(&'s str) -> ParseResult<'s, ModificationId> + Captures<(&'c (), &'a (), &'p ())> {
428+
) -> impl FnMut(&'s str) -> ParseResult<'s, ModificationId> {
443429
let chemical_composition = chemical_composition(polymer.borrow().atomic_db());
444430
let parser = tuple((offset_kind, opt(multiplier), chemical_composition));
445431

@@ -535,7 +521,9 @@ pub enum ConstructionError {
535521
PolychemError(#[from] Box<PolychemError>),
536522

537523
// FIXME: Eventually make this error either more informative (printing the number of each), or replace it!
538-
#[error("the number of described crosslinks (e.g. 3-3) doesn't match the number of crosslink connectors (=)")]
524+
#[error(
525+
"the number of described crosslinks (e.g. 3-3) doesn't match the number of crosslink connectors (=)"
526+
)]
539527
CrosslinkCountMismatch,
540528

541529
// FIXME: Eventually make this error either more informative, or replace it!
@@ -553,7 +541,9 @@ pub enum ConstructionError {
553541

554542
#[derive(Clone, Eq, PartialEq, Debug, Diagnostic, Error)]
555543
pub enum MuropeptideErrorKind {
556-
#[error("expected an ASCII letter, optionally followed by any number of ASCII letters, digits, and underscores")]
544+
#[error(
545+
"expected an ASCII letter, optionally followed by any number of ASCII letters, digits, and underscores"
546+
)]
557547
ExpectedIdentifier,
558548

559549
// FIXME: Kill this and merge into the error below!

crates/nom-miette/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "nom-miette"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55

66
[dependencies]
77
ahash = "0.8.11"

crates/nom-miette/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use std::fmt::Display;
44
use ahash::{HashMap, HashMapExt};
55
use miette::{Diagnostic, LabeledSpan, SourceSpan};
66
use nom::{
7+
Err, ErrorConvert, Finish, IResult, Parser,
78
combinator::{all_consuming, complete, consumed},
89
error::ParseError,
9-
Err, ErrorConvert, Finish, IResult, Parser,
1010
};
1111
use thiserror::Error;
1212

crates/polychem/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "polychem"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55

66
# FIXME: Set up justfile and CI to check direct-minimal-versions
77
[dependencies]

crates/polychem/benches/api.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use divan::{black_box, AllocProfiler};
1+
use divan::{AllocProfiler, black_box};
22
use once_cell::sync::Lazy;
33
use polychem::{
4-
atoms::atomic_database, AtomicDatabase, Charged, ChemicalComposition, Massive, PolymerDatabase,
4+
AtomicDatabase, Charged, ChemicalComposition, Massive, PolymerDatabase, atoms::atomic_database,
55
};
66

77
#[global_allocator]

crates/polychem/src/atoms/atomic_database.rs

+13-19
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ use std::{num::NonZero, ops::Deref, str::FromStr};
44
// External Crate Imports
55
use ahash::HashMap;
66
use knuffel::{
7+
Decode, DecodeScalar,
78
ast::{self, Integer, Literal, Radix, TypeName},
89
decode::{Context, Kind},
910
errors::{DecodeError, ExpectedType},
1011
span::Spanned,
1112
traits::ErrorSpan,
12-
Decode, DecodeScalar,
1313
};
1414
use miette::{Diagnostic, Result};
1515
use rust_decimal::Decimal;
@@ -287,13 +287,10 @@ impl From<IsotopeKdl> for IsotopeEntry {
287287
abundance,
288288
}: IsotopeKdl,
289289
) -> Self {
290-
(
291-
MassNumber(mass_number.0),
292-
Isotope {
293-
relative_mass: Mass(relative_mass.0),
294-
abundance: abundance.map(|a| Abundance(a.0)),
295-
},
296-
)
290+
(MassNumber(mass_number.0), Isotope {
291+
relative_mass: Mass(relative_mass.0),
292+
abundance: abundance.map(|a| Abundance(a.0)),
293+
})
297294
}
298295
}
299296

@@ -308,14 +305,11 @@ impl From<ParticleKdl> for ParticleEntry {
308305
charge,
309306
}: ParticleKdl,
310307
) -> Self {
311-
(
312-
symbol.0,
313-
ParticleDescription {
314-
name,
315-
mass: Mass(mass.0),
316-
charge: Charge(charge),
317-
},
318-
)
308+
(symbol.0, ParticleDescription {
309+
name,
310+
mass: Mass(mass.0),
311+
charge: Charge(charge),
312+
})
319313
}
320314
}
321315

@@ -461,14 +455,14 @@ mod tests {
461455
fn decimal_scientific() {
462456
let kdl = "lossless 5.485_799_090_65e-4";
463457
let res = knuffel::parse::<Vec<Lossless>>("test", kdl).unwrap();
464-
assert_eq!(res[0].0 .0, dec!(0.000548579909065));
458+
assert_eq!(res[0].0.0, dec!(0.000548579909065));
465459
}
466460

467461
#[test]
468462
fn decimal_from_integer() {
469463
let kdl = "lossless 1";
470464
let res = knuffel::parse::<Vec<Lossless>>("test", kdl).unwrap();
471-
assert_eq!(res[0].0 .0, dec!(1));
465+
assert_eq!(res[0].0.0, dec!(1));
472466
}
473467

474468
#[test]
@@ -499,7 +493,7 @@ mod tests {
499493
fn nonzero_positive() {
500494
let kdl = "nonzero 42";
501495
let res = knuffel::parse::<Vec<NonZero>>("test", kdl).unwrap();
502-
assert_eq!(res[0].0 .0.get(), 42);
496+
assert_eq!(res[0].0.0.get(), 42);
503497
}
504498

505499
#[test]

0 commit comments

Comments
 (0)