Hi,
sorry to post here frequently, as I learn more about rust, I am getting glued to it and this forum is the only place to rescue when I am stuck. I have to strip my code to make the question shorter.
Iteration 1(No compilation error, all good)
pub fn setbaud (instance: u8, clk: Clock, baud: Baud){
unsafe {
match(clk, baud){
(Clock::F2Mhz, Baud::R31250) => (*uartx).div = 63,
(Clock::F2Mhz, Baud::R115200) => (*uartx).div = 16,
Iteration 2 - tried to take in as reference and dereferencing in match (compilation error)
pub fn setbaud (instance: u8, clk: &Clock, baud: &Baud){
unsafe {
match(*clk, *baud){
(Clock::F2Mhz, Baud::R31250) => (*uartx).div = 63,
(Clock::F2Mhz, Baud::R115200) => (*uartx).div = 16,
Throws following error and could n't understand.
match(clk, baud){
** | ^^^^^ move occurs because *baud
has type Baud
, which does not implement the Copy
trait
Iteration 3 (NO compilation error without dereferecing)
pub fn setbaud (instance: u8, clk: &Clock, baud: &Baud){
unsafe {
match(clk, baud){
(Clock::F2Mhz, Baud::R31250) => (*uartx).div = 63,
(Clock::F2Mhz, Baud::R115200) => (*uartx).div = 16,
My main question here is how iteration 3 did NOT throw any compilation error?
Coz, parameters are reference, but matched without dereferencing it.