Skip to content

Commit 72f0abf

Browse files
committed
chore: clippy
1 parent 6545cb1 commit 72f0abf

File tree

3 files changed

+62
-14
lines changed

3 files changed

+62
-14
lines changed

src/io/mzml/reader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ impl<'inner, C: CentroidLike, D: DeconvolutedCentroidLike>
525525

526526
fn precursor_mut(&mut self) -> &mut Precursor {
527527
if self.precursor.is_empty() {
528-
return self.new_precursor_mut()
528+
self.new_precursor_mut()
529529
} else {
530530
self.precursor.last_mut().unwrap()
531531
}

src/params.rs

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,28 +1236,28 @@ macro_rules! curie {
12361236
$crate::params::CURIE::new($crate::params::ControlledVocabulary::MS, $acc)
12371237
};
12381238
(UO:$acc:literal) => {
1239-
$crate::params::CURIE::new($crate::params::ControlledVocabulary::UO, $acc)
1239+
$crate::params::CURIE { controlled_vocabulary: $crate::params::ControlledVocabulary::UO, accession: $acc }
12401240
};
12411241
(EFO:$acc:literal) => {
1242-
$crate::params::CURIE::new($crate::params::ControlledVocabulary::EFO, $acc)
1242+
$crate::params::CURIE { controlled_vocabulary: $crate::params::ControlledVocabulary::EFO, accession: $acc }
12431243
};
12441244
(BFO:$acc:literal) => {
1245-
$crate::params::CURIE::new($crate::params::ControlledVocabulary::BFO, $acc)
1245+
$crate::params::CURIE { controlled_vocabulary: $crate::params::ControlledVocabulary::BFO, accession: $acc }
12461246
};
12471247
(BTO:$acc:literal) => {
1248-
$crate::params::CURIE::new($crate::params::ControlledVocabulary::BTO, $acc)
1248+
$crate::params::CURIE { controlled_vocabulary: $crate::params::ControlledVocabulary::BTO, accession: $acc }
12491249
};
12501250
(OBI:$acc:literal) => {
1251-
$crate::params::CURIE::new($crate::params::ControlledVocabulary::OBI, $acc)
1251+
$crate::params::CURIE { controlled_vocabulary: $crate::params::ControlledVocabulary::OBI, accession: $acc }
12521252
};
12531253
(HANCESTRO:$acc:literal) => {
1254-
$crate::params::CURIE::new($crate::params::ControlledVocabulary::HANCESTRO, $acc)
1254+
$crate::params::CURIE { controlled_vocabulary: $crate::params::ControlledVocabulary::HANCESTRO, accession: $acc }
12551255
};
12561256
(NCIT:$acc:literal) => {
1257-
$crate::params::CURIE::new($crate::params::ControlledVocabulary::NCIT, $acc)
1257+
$crate::params::CURIE { controlled_vocabulary: $crate::params::ControlledVocabulary::NCIT, accession: $acc }
12581258
};
12591259
(PRIDE:$acc:literal) => {
1260-
$crate::params::CURIE::new($crate::params::ControlledVocabulary::PRIDE, $acc)
1260+
$crate::params::CURIE { controlled_vocabulary: $crate::params::ControlledVocabulary::PRIDE, accession: $acc }
12611261
};
12621262
}
12631263

@@ -1287,6 +1287,30 @@ impl CURIE {
12871287
}
12881288
}
12891289

1290+
/// A CURIE is a namespace + accession identifier
1291+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1292+
struct PackedCURIE(u64);
1293+
1294+
#[allow(unused)]
1295+
impl PackedCURIE {
1296+
pub fn from_curie(curie: CURIE) -> Self {
1297+
let cv = curie.controlled_vocabulary();
1298+
let cv_id = cv as u64;
1299+
let acc_code = curie.accession_int();
1300+
let code = acc_code as u64;
1301+
Self(cv_id << 56 | code)
1302+
}
1303+
1304+
pub fn accession(&self) -> u64 {
1305+
self.0 & 0x00ffffffffffffff
1306+
}
1307+
1308+
pub fn controlled_vocabulary(&self) -> ControlledVocabulary {
1309+
((self.0 & 0xff00000000000000) as u8).try_into().unwrap()
1310+
}
1311+
}
1312+
1313+
12901314
impl Display for CURIE {
12911315
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12921316
write!(
@@ -1896,9 +1920,10 @@ impl Hash for Param {
18961920
/// Controlled vocabularies used in mass spectrometry data files
18971921
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
18981922
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1923+
#[repr(u8)]
18991924
pub enum ControlledVocabulary {
19001925
/// The PSI-MS Controlled Vocabulary [https://www.ebi.ac.uk/ols4/ontologies/ms](https://www.ebi.ac.uk/ols4/ontologies/ms)
1901-
MS,
1926+
MS = 1,
19021927
/// The Unit Ontology [https://www.ebi.ac.uk/ols4/ontologies/uo](https://www.ebi.ac.uk/ols4/ontologies/uo)
19031928
UO,
19041929
/// The Experimental Factor Ontology <https://www.ebi.ac.uk/ols4/ontologies/efo>
@@ -1938,6 +1963,26 @@ const BTO_CV_BYTES: &[u8] = BTO_CV.as_bytes();
19381963
const NCIT_CV_BYTES: &[u8] = NCIT_CV.as_bytes();
19391964
const PRIDE_CV_BYTES: &[u8] = PRIDE_CV.as_bytes();
19401965

1966+
1967+
impl TryFrom<u8> for ControlledVocabulary {
1968+
type Error = ControlledVocabularyResolutionError;
1969+
1970+
fn try_from(value: u8) -> Result<Self, Self::Error> {
1971+
match value {
1972+
1 => Ok(Self::MS),
1973+
2 => Ok(Self::UO),
1974+
3 => Ok(Self::EFO),
1975+
4 => Ok(Self::OBI),
1976+
5 => Ok(Self::HANCESTRO),
1977+
6 => Ok(Self::BFO),
1978+
7 => Ok(Self::NCIT),
1979+
8 => Ok(Self::BTO),
1980+
9 => Ok(Self::PRIDE),
1981+
_ => Err(ControlledVocabularyResolutionError::UnknownControlledVocabularyCode(value)),
1982+
}
1983+
}
1984+
}
1985+
19411986
/// Anything that can be converted into an accession code portion of a [`CURIE`]
19421987
#[derive(Debug, Clone)]
19431988
pub enum AccessionLike<'a> {
@@ -2119,11 +2164,14 @@ impl<'a> ControlledVocabulary {
21192164
}
21202165
}
21212166

2122-
#[doc(hidden)]
2167+
/// An error describing a failure to map a controlled vocabulary identifier
2168+
/// to a known namespace
21232169
#[derive(Debug, Clone, Error)]
21242170
pub enum ControlledVocabularyResolutionError {
21252171
#[error("Unrecognized controlled vocabulary {0}")]
21262172
UnknownControlledVocabulary(String),
2173+
#[error("Unrecognized controlled vocabulary code {0}")]
2174+
UnknownControlledVocabularyCode(u8)
21272175
}
21282176

21292177
impl FromStr for ControlledVocabulary {

src/spectrum/spectrum_types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,16 +1285,16 @@ where
12851285
let peak_data: PeakDataLevel<C, D> = PeakDataLevel::try_from(arrays)?;
12861286
match peak_data {
12871287
PeakDataLevel::Missing => {
1288-
return Ok(RefPeakDataLevel::Missing)
1288+
Ok(RefPeakDataLevel::Missing)
12891289
},
12901290
PeakDataLevel::RawData(_) => panic!("not possible"),
12911291
PeakDataLevel::Centroid(peak_set_vec) => {
12921292
self.peaks = Some(peak_set_vec);
1293-
return Ok(self.peaks())
1293+
Ok(self.peaks())
12941294
},
12951295
PeakDataLevel::Deconvoluted(peak_set_vec) => {
12961296
self.deconvoluted_peaks = Some(peak_set_vec);
1297-
return Ok(self.peaks())
1297+
Ok(self.peaks())
12981298
},
12991299
}
13001300
} else {

0 commit comments

Comments
 (0)