rust-embedded / embedded-hal

A Hardware Abstraction Layer (HAL) for embedded systems
Apache License 2.0
1.95k stars 197 forks source link

How add inputs to vector? #508

Closed hanusek closed 1 year ago

hanusek commented 1 year ago

Hello! I have a problem with generics in Rust. I would like to add input to the vector.

Example 1:

[..]
let d_in1 = gpiod.pd7.into_floating_input(&mut gpiod.crl);
let d_in2 = gpiod.pd6.into_floating_input(&mut gpiod.crl);
let v = [d_in1, d_in2];

Error:

    |
200 |                 let v = [d_in1, d_in2];
    |                                 ^^^^^ expected `7`, found `6`
    |
    = note: expected struct `stm32f1xx_hal::gpio::Pin<_, _, 7>`
               found struct `stm32f1xx_hal::gpio::Pin<_, _, 6>`

Example 2:

[...]
let d_in1 = gpiod.pd7.into_floating_input(&mut gpiod.crl);
let d_in2 = gpiod.pd6.into_floating_input(&mut gpiod.crl);

let v = heapless::Vec::new();
v.push(d_in1);
v.push(d_in2);

Error:

203 |                 v.push(d_in1);
    |                 -      ----- this argument has type `stm32f1xx_hal::gpio::Pin<'D', 7>`...
    |                 |
    |                 ... which causes `v` to have type `Vec<stm32f1xx_hal::gpio::Pin<'D', 7>, _>`
204 |                 v.push(d_in2);
    |                   ---- ^^^^^ expected `7`, found `6`
    |                   |
    |                   arguments to this method are incorrect
    |
    = note: expected struct `stm32f1xx_hal::gpio::Pin<_, _, 7>`
               found struct `stm32f1xx_hal::gpio::Pin<_, _, 6>`
help: the return type of this call is `stm32f1xx_hal::gpio::Pin<'D', 6>` due to the type of the argument passed
   --> app/src/main.rs:204:17
    |
204 |                 v.push(d_in2);
    |                 ^^^^^^^-----^
    |                        |
    |                        this argument influences the return type of `push`

How to fix it?

Dirbaio commented 1 year ago

this is not an issue in embedded-hal, you should ask in the stm32f1xx-hal issue tracker