-
Notifications
You must be signed in to change notification settings - Fork 154
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
Generic Part1 #347
Generic Part1 #347
Conversation
r? @therealprof (rust_highfive has picked a reviewer for you, use r? to override) |
cc @therealprof
Now all right. It also depends on #358. |
ef62cc3
to
9fd21ec
Compare
cc @Disasm |
@therealprof I've rebased this on master. Test, please. |
impl<U, REG> Reg<U, REG> | ||
where | ||
Self: Writable, | ||
U: Copy + Default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this Default
equals to "returns zero"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is for bool
, u8
, u16
u32
and u64
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but these types are not enforced I guess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are enforced by size type of register or field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it's possible to create a wrapper with the same size and a custom Default impl that returns reset value, for example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How? All fields are private. You can get register only from peripheral as it was before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, now I see. Thanks.
|
It was auto-implementation? |
Yes, I think that was due to the inner |
As discussed on Matrix, documentation becomes even more difficult to understand with this change: it's unclear how to read and write registers, also there is no information about field variants. |
TBH I'm not too sure whether we really need that |
@therealprof Yes, but it's better to have |
error[E0658]: negative trait bounds are not yet fully implemented; use marker types for now What to do with this? |
I think that PhantomData with some weird type can help |
Can you write how you see implementation for |
Seems like |
I've added |
What you mean |
@burrbull It's no longer accessible from the register documentation pages. Only on upper levels. |
Can you show example? |
spi0::RegisterBlock -> CTRLR0 -> R -> WORK_MODER |
Here is one breaking change (#354). Reader now have same as writer: And now you can use this enum for both read and write: let v = spi.ctrl0.read().work_mode().variant();
...
spi.ctrl0.write(|w| w.work_mode().variant(v)); // Before now incompatible types error was here. |
@therealprof I can't find where is source of this documentation https://docs.rs/svd2rust ? |
@burrbull You mean |
src/generate/generic.rs
Outdated
///Register size | ||
type Size; | ||
///Reset value of the register | ||
fn reset_value() -> Self::Size; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This associated type name is debatable, but I'm not going to force my point of view here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed Size on Type
|
||
let doc = format!("`read()` method returns [{0}::R]({0}::R) reader structure", &name_sc); | ||
if can_read { | ||
out.push(quote! { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not move the let doc = ...
inside the if
clause? Should be cheaper to compute and avoids the risk of accidentally using it in a wrong context.
}); | ||
} | ||
let doc = format!("`write(|w| ..)` method takes [{0}::W]({0}::W) writer structure", &name_sc); | ||
if can_write { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
Also please rebase and make sure the commits have a meaningful commit message. |
Rebased. |
bors try |
tryBuild succeeded |
@Disasm Still happy? |
@therealprof yes, looks good. |
In general, I'd improve documentation for generic methods (read/write/...), replacing references to the book with short examples. |
bors r+ |
347: Generic Part1 r=Disasm a=burrbull Rebased and reopened. Co-authored-by: Andrey Zgarbul <[email protected]>
Build succeeded |
Rebased and reopened.