by geogriffin · 5y ago · 0 comments
fn read_keys(#[cfg(feature = "splitapple")]
port: nrf52840_hal::pac::P1,
#[cfg(feature = "keytron")]
port: nrf52833_hal::pac::P0) -> Packet {}
I suppose the compiler could try to suggest that as a fix. #[cfg(feature = "splitapple")]
type Port = nrf52840_hal::pac::P1;
#[cfg(feature = "keytron")]
type Port = nrf52833_hal::pac::P0;
fn read_keys(port: Port) -> Packet {}
but I think the whole problem here is that author tried to do what would have been #ifdef in C, but that doesn't get you far in Rust when macros are AST-based and types are more specific than `int` and `char*`.A more "rustic" solution would be to use a trait, e.g.
trait ReadKeys {
type Port;
fn read_keys(Self::Port) -> Packet {}
}
impl ReadKeys for Splitapple {…}
impl ReadKeys for Keytron {…}