Long compilation - Many From implementation

I currently work on the stm32g4xx-hal and I try to create a "good" way to change the mode of each pins.
I want to guarantee that the pins are always in a good state, especially with alternate mode, not all pins can be on all alternate mode.
My current implementation seems to work, but it takes more than 1h to compile on my computer. I think it's linked with the amount of "From" implementation, more than 35000 according to a simple cargo expand.
Do you know a way to make the compilation faster or an other way to have such guarantee at compile time ?

Creating tens of thousands of From impls is certainly not the right way. What guarantees do you want to ensure specifically?

I have those structs:

#[derive(Default)]
pub struct OpenDrain;
#[derive(Default)]
pub struct PushPull;
// ...
#[derive(Default)]
pub struct Alternate<const A: u8, MODE = PushPull> {
    _mode: PhantomData<MODE>,
}

The MODE generic of Pin can be any of Flaoting, PushPull... and you can change the mode at runtime.
But for some pins (for example Pin<'A', 1>) the mode Alternate<4> is invalid, so I want to guarantee that the pin will never be in this mode.

I use the From trait to convert between all of these modes, by only implementing when the conversion is valid.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.