Open AdinAck opened 1 month ago
I don't believe my proposal is related to that. I don't want to return the writer, in fact, the proposed body of write
forbids T
ever being W
or &mut W
since bits
is moved out of the writer for register.set
, no?
Ok yes I believe I set up an analogous setup in rust playground:
#[derive(Debug)]
struct Bits(u32);
#[derive(Debug)]
struct W {
bits: Bits,
_reg: (),
}
fn consume_bits(Bits(num): Bits) {
println!("bits: {}", num);
}
fn write<F, T>(f: F) -> T
where
F: FnOnce(&mut W) -> T,
{
let mut writer = W { bits: Bits(0), _reg: () };
let result = f(&mut writer);
consume_bits(writer.bits);
result
}
fn main() {
let outside = write(|_w| 0xaa);
// let outside = write(|w| w); <- does not compile
println!("outisde: {:?}", outside);
}
So I don't believe this introduces any complications as mentioned in #738.
Sorry for waiting. Looks interesting. I think you could nominate it for next meeting: https://github.com/rust-embedded/wg/discussions/800
No problem, you have a lot oh your hands. I've never done that before so I don't know the proper procedure.
Moved from
stm32-rs-nightlies
I ran into an issue when writing to a register where I wanted to return a value from the write, like this:
But, the signature of
write
forbids this:So I'm curious, why not change the signature to:
By implementing it like this:
Is there a drawback to this?