-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Just another issue to ask for a green-light from you before I put in a PR!
I was working on writing a function like this:
fn from_mzdata_peaks<D>(peaks: RefPeakDataLevel<CentroidPeak, D>) -> Result<Self> {
todo!()
}And I don't care at all about D— if this function encounters anything other than the centroided m/z values, it will error — but that code doesn't currently compile:
error[E0277]: the trait bound `D: IndexedCoordinate<mzdata::mzpeaks::Mass>` is not satisfied
--> crates/sifter/src/lib.rs:88:36
|
88 | fn from_mzdata_peaks<D>(peaks: RefPeakDataLevel<CentroidPeak, D>) -> Result<Self> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IndexedCoordinate<mzdata::mzpeaks::Mass>` is not implemented for `D`
|
= note: required for `D` to implement `DeconvolutedCentroidLike`
note: required by a bound in `RefPeakDataLevel`
--> /home/tll/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/mzdata-0.60.3/src/spectrum/peaks.rs:568:51
|
568 | pub enum RefPeakDataLevel<'a, C: CentroidLike, D: DeconvolutedCentroidLike> {
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `RefPeakDataLevel`
help: consider restricting type parameter `D` with trait `IndexedCoordinate`
|
88 | fn from_mzdata_peaks<D: mzdata::prelude::IndexedCoordinate<mzdata::mzpeaks::Mass>>(peaks: RefPeakDataLevel<CentroidPeak, D>) -> Result<Self> {
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
error[E0277]: the trait bound `D: IntensityMeasurement` is not satisfied
--> crates/sifter/src/lib.rs:88:36
|
88 | fn from_mzdata_peaks<D>(peaks: RefPeakDataLevel<CentroidPeak, D>) -> Result<Self> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntensityMeasurement` is not implemented for `D`
|
= note: required for `D` to implement `DeconvolutedCentroidLike`
note: required by a bound in `RefPeakDataLevel`
--> /home/tll/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/mzdata-0.60.3/src/spectrum/peaks.rs:568:51
|
568 | pub enum RefPeakDataLevel<'a, C: CentroidLike, D: DeconvolutedCentroidLike> {
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `RefPeakDataLevel`
help: consider restricting type parameter `D` with trait `IntensityMeasurement`
|
88 | fn from_mzdata_peaks<D: mzdata::prelude::IntensityMeasurement>(peaks: RefPeakDataLevel<CentroidPeak, D>) -> Result<Self> {
| +++++++++++++++++++++++++++++++++++++++
error[E0277]: the trait bound `D: KnownCharge` is not satisfied
--> crates/sifter/src/lib.rs:88:36
|
88 | fn from_mzdata_peaks<D>(peaks: RefPeakDataLevel<CentroidPeak, D>) -> Result<Self> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `KnownCharge` is not implemented for `D`
|
= note: required for `D` to implement `DeconvolutedCentroidLike`
note: required by a bound in `RefPeakDataLevel`
--> /home/tll/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/mzdata-0.60.3/src/spectrum/peaks.rs:568:51
|
568 | pub enum RefPeakDataLevel<'a, C: CentroidLike, D: DeconvolutedCentroidLike> {
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `RefPeakDataLevel`
help: consider restricting type parameter `D` with trait `KnownCharge`
|
88 | fn from_mzdata_peaks<D: mzdata::prelude::KnownCharge>(peaks: RefPeakDataLevel<CentroidPeak, D>) -> Result<Self> {
| ++++++++++++++++++++++++++++++
Of course, if I add in a bound for D, I can get it to compile:
fn from_mzdata_peaks<D: DeconvolutedCentroidLike>(
peaks: RefPeakDataLevel<CentroidPeak, D>,
) -> Result<Self> {
todo!()
}But really, that's not a bound that's needed for anything I'll be doing in this function, since I'll only ever touch the Centroid(&'a MZPeakSetType<C>) variant (where there is no D).
Putting bounds on structs and enums directly (instead of just on the impl blocks) is something I've done in the past, but it seems like poor practice (https://stackoverflow.com/a/66369912/2395870) and indeed it's causing me some issues here.
Let me know if you'd like me to put in a PR to remove all of those! I think it should be a totally semver compatible change — nothing breaking, just allowing users more flexibility than before!