Cannot return a trait object of two traits

Viewed 56

I wrote a function that returns a Box of a trait object that is made of two traits.

fn get_gpio(pin: &u8) -> Result<Box<dyn InputOutputPin>, &'static str>{
    match pin {
        33 => Ok(Box::new(Peripherals::take().unwrap().pins.gpio33.into_input_output().unwrap())),
        32 => Ok(Box::new(Peripherals::take().unwrap().pins.gpio32.into_input_output().unwrap())),
        27 => Ok(Box::new(Peripherals::take().unwrap().pins.gpio27.into_input_output().unwrap())),
        26 => Ok(Box::new(Peripherals::take().unwrap().pins.gpio26.into_input_output().unwrap())),
        25 => Ok(Box::new(Peripherals::take().unwrap().pins.gpio25.into_input_output().unwrap())),
        _ => Err("Pin not configurable for dht")
    }
}

With the trait being:

trait InputOutputPin: InputPin<Error = EspError> + OutputPin<Error = EspError>{}

InputPin and OutputPin are traits defined by the esp idf library.

The only thing I am trying to do is to return a Gpio, but they are defined by a macro to be specific gpios. Because I want the function to return different gpios I cannot use the a specific return type like Gpio1<InputOutput>.

How can this be solved?

0 Answers
Related