rustyms/peptidoform/
complexity.rs

1//! Defines the different levels of complexity a peptide can be.
2//! Used for compile time checking for incorrect use of peptides.
3use serde::{Deserialize, Serialize};
4
5/// A [`crate::Peptidoform`] that (potentially) is linked, either with cross-links or branches
6#[derive(
7    Debug, Default, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash, Serialize, Deserialize,
8)]
9pub struct Linked;
10
11/// A [`crate::Peptidoform`] that is not cross-linked or branched, but can use the whole breath of the complexity otherwise
12#[derive(
13    Debug, Default, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash, Serialize, Deserialize,
14)]
15pub struct Linear;
16
17/// A [`crate::Peptidoform`] that does not have any of the following:
18/// * Labile modifications
19/// * Global isotope modifications
20/// * Charge carriers, use of charged ions apart from protons
21/// * Cyclic structures: inter/intra cross-links or branches
22#[derive(
23    Debug, Default, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash, Serialize, Deserialize,
24)]
25pub struct SimpleLinear;
26
27/// A [`crate::Peptidoform`] that does not have any of the following:
28/// * Ambiguous modifications
29/// * Ambiguous amino acid sequence `(?AA)`
30///
31/// On top of the outlawed features in [`SimpleLinear`].
32#[derive(
33    Debug, Default, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash, Serialize, Deserialize,
34)]
35pub struct SemiAmbiguous;
36
37/// A [`crate::Peptidoform`] that does not have any of the following:
38/// * Ambiguous amino acids (B/Z)
39///
40/// On top of the outlawed features in [`SemiAmbiguous`].
41#[derive(
42    Debug, Default, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash, Serialize, Deserialize,
43)]
44pub struct UnAmbiguous;
45
46/// Indicate that a peptide has at max this level of complexity, or lower.
47/// `Self` will always be the highest (or identical) of the two complexities.
48pub trait AtMax<T> {}
49impl<T> AtMax<T> for T {}
50impl AtMax<Linked> for Linear {}
51impl AtMax<Linked> for SimpleLinear {}
52impl AtMax<Linked> for SemiAmbiguous {}
53impl AtMax<Linked> for UnAmbiguous {}
54impl AtMax<Linear> for SimpleLinear {}
55impl AtMax<Linear> for SemiAmbiguous {}
56impl AtMax<Linear> for UnAmbiguous {}
57impl AtMax<SimpleLinear> for SemiAmbiguous {}
58impl AtMax<SimpleLinear> for UnAmbiguous {}
59impl AtMax<SemiAmbiguous> for UnAmbiguous {}
60
61/// Indicate that a peptide has at least this level of complexity, or higher.
62/// The type parameter will always be the highest (or identical) of the two complexities.
63pub trait AtLeast<T> {}
64impl<T> AtLeast<T> for T {}
65impl AtLeast<Linear> for Linked {}
66impl AtLeast<SimpleLinear> for Linked {}
67impl AtLeast<SemiAmbiguous> for Linked {}
68impl AtLeast<UnAmbiguous> for Linked {}
69impl AtLeast<SimpleLinear> for Linear {}
70impl AtLeast<SemiAmbiguous> for Linear {}
71impl AtLeast<UnAmbiguous> for Linear {}
72impl AtLeast<SemiAmbiguous> for SimpleLinear {}
73impl AtLeast<UnAmbiguous> for SimpleLinear {}
74impl AtLeast<UnAmbiguous> for SemiAmbiguous {}
75
76/// Type level max between two complexity levels. The highest of the two levels is stored in the
77/// associated type `HighestLevel`.
78pub trait HighestOf<T> {
79    /// This is the highest complexity level out of Self and the type parameter
80    type HighestLevel;
81}
82impl<T> HighestOf<T> for T {
83    type HighestLevel = T;
84}
85impl HighestOf<Linked> for Linear {
86    type HighestLevel = Linked;
87}
88impl HighestOf<Linked> for SimpleLinear {
89    type HighestLevel = Linked;
90}
91impl HighestOf<Linked> for SemiAmbiguous {
92    type HighestLevel = Linked;
93}
94impl HighestOf<Linked> for UnAmbiguous {
95    type HighestLevel = Linked;
96}
97impl HighestOf<Linear> for SimpleLinear {
98    type HighestLevel = Linear;
99}
100impl HighestOf<Linear> for SemiAmbiguous {
101    type HighestLevel = Linear;
102}
103impl HighestOf<Linear> for UnAmbiguous {
104    type HighestLevel = Linear;
105}
106impl HighestOf<SimpleLinear> for SemiAmbiguous {
107    type HighestLevel = SimpleLinear;
108}
109impl HighestOf<SimpleLinear> for UnAmbiguous {
110    type HighestLevel = SimpleLinear;
111}
112impl HighestOf<SemiAmbiguous> for UnAmbiguous {
113    type HighestLevel = SemiAmbiguous;
114}
115impl HighestOf<Linear> for Linked {
116    type HighestLevel = Self;
117}
118impl HighestOf<SimpleLinear> for Linked {
119    type HighestLevel = Self;
120}
121impl HighestOf<SemiAmbiguous> for Linked {
122    type HighestLevel = Self;
123}
124impl HighestOf<UnAmbiguous> for Linked {
125    type HighestLevel = Self;
126}
127impl HighestOf<SimpleLinear> for Linear {
128    type HighestLevel = Self;
129}
130impl HighestOf<SemiAmbiguous> for Linear {
131    type HighestLevel = Self;
132}
133impl HighestOf<UnAmbiguous> for Linear {
134    type HighestLevel = Self;
135}
136impl HighestOf<SemiAmbiguous> for SimpleLinear {
137    type HighestLevel = Self;
138}
139impl HighestOf<UnAmbiguous> for SimpleLinear {
140    type HighestLevel = Self;
141}
142impl HighestOf<UnAmbiguous> for SemiAmbiguous {
143    type HighestLevel = Self;
144}