mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2024-12-24 05:01:31 +11:00
f8984a9eac
Implementing `impl From<SystemClock> for Hertz` is a footgun, as SystemClock is not Copy, so the automatic conversion consumes the owned clock. This is visible in the example i2c.rs: ``` let mut i2c = hal::I2C::i2c1( pac.I2C1, sda_pin, scl_pin, // Try `not_an_scl_pin` here 400.kHz(), &mut pac.RESETS, clocks.peripheral_clock, ); ``` If the user wants to use both `i2c0` and `i2c1` at the same time, copying from this example won't work: ``` error[E0382]: use of moved value: `clocks.peripheral_clock` --> rp2040-hal/examples/i2c.rs:106:9 | 97 | clocks.peripheral_clock, | ----------------------- value moved here ... 106 | clocks.peripheral_clock, | ^^^^^^^^^^^^^^^^^^^^^^^ value used here after move | = note: move occurs because `clocks.peripheral_clock` has type `PeripheralClock`, which does not implement the `Copy` trait ``` As getting the frequency from a clock doesn't really need ownership, changing it to `impl From<&SystemClock> for Hertz` is both more logical and provides better usability. This is, however, a breaking change: Code relying on this trait implementation needs to be changed by adding a `&`. |
||
---|---|---|
.. | ||
adc.rs | ||
blinky.rs | ||
dht11.rs | ||
gpio_in_out.rs | ||
gpio_irq_example.rs | ||
i2c.rs | ||
lcd_display.rs | ||
multicore_fifo_blink.rs | ||
multicore_polyblink.rs | ||
pio_blink.rs | ||
pio_proc_blink.rs | ||
pio_side_set.rs | ||
pio_synchronized.rs | ||
pwm_blink.rs | ||
rom_funcs.rs | ||
spi.rs | ||
uart.rs | ||
watchdog.rs |