-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Register Write Limitation #859
Comments
I don't believe my proposal is related to that. I don't want to return the writer, in fact, the proposed body of |
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: rust-embedded/wg#800 |
No problem, you have a lot oh your hands. I've never done that before so I don't know the proper procedure. |
Do your suggestion require changing of signatures of In other words can we use traditional field modifying system simultaneously with yours? |
Just write and modify, all the field writers work as is! |
I'm going to turn this issue into a PR so exactly what I'm proposing is visible. |
I understand what you want, but I not sure what is better:
I prefer second as less breaking. |
Ah I hadn't even thought of that, two good options! I agree, it took me like 3 hours to convert all I'll still make a PR but as an addition rather than a change. |
Resolved by #874. |
@AdinAck I've released current state of You could use it as: [dependencies.stm32g4]
package = "stm32g4-staging"
version = "0.17.0" |
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?
The text was updated successfully, but these errors were encountered: