-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
Should RW1C bit fields have set_xxx
and clear_xxx
which do actually *set* and *clear* bits?
#152
Comments
To prevent that said confusion, method docs should specify whether each method actually assigns 0 or 1.
Of course, we can rename either Off-topic: suggestions about renaming (which may lead to a breaking change)
fn assign_xxx(&mut self, bit: bool) -> &mut Self {
if bit { self.set_xxx() }
else { self.clear_xxx() }
} This, however, is an inconsistent naming convention since field setters are And here's my second thought: within this crate, fix the verb 'raise' for the write-1-to-set-1 action, and use 'set' to only indicate the assignment. To sum up, our final bit setter methods and their documentations would be something like: (RW bits)
(RW1S bits)
(RW1C bits)
Sorry for my delaying response (on this, and another PR I'd created) but I feel stuck on my personal project. |
Thanks for the suggestion, and sorry for the delay.
Certainly, it's good to mention whether a method sets 0 or 1. It's so great that it doesn't need a breaking change, although I'm not sure how many users will read the docs to check the actual behavior of setters and clearers.
I understand the purpose of renaming
Initially, this crate provided
"raise" is somewhat a good choice. Although I haven't seen a case where the word was used to mean setting 1, it can easily be associated with the operation. I think "set" and "assign" are better, however, as many people use "set" to assign 1 (Google search result) and "assign" means exactly what the method does.
I'm not sure whether letting different types of bits have different names for the same operations is good. On the one hand, users can notice the misrecognition of bit types by compile errors. On the other hand, such method names are somewhat confusing, and it might be better to let all bits have the same names and same operations (e.g., set, clear, assign for assigning 1, 0, the passed value, respectively), and write docs what and which bits are RW/RO/RW1C/RW1S and a note about handling RW1C. To sum up, we can clearly whether a method sets 1 or 0 by updating the docs without introducing a breaking change. For renaming methods, using "set", "clear" (, and "assign" if necessary) are better.
No problem. I'm too delayed. |
Currently For example, I wanted to clear PORTSC CSC bit of registers.port_register_set.structural_at_mut(i).portsc.update_volatile(|portsc| {
portsc.assign_connect_status_change(true);
}); (allow me to use structural indexing syntax here for convenience.) And for the alternatives of hypothetical (but good-to-have) Personally I don't want others spend their time only for confirming what a method actually does. If the behaviors were well-documented, at least modern-IDE users just like me will immediately read them when a method is selected from the autocomplete menu, and that's enough. |
Certainly, you're correct, and we should describe whether a method sets 0 or 1. Are you going to write them, or do I do? For the methods, after my second thought, it may be better to define only the |
Made it. #160 RW1C docs are now
|
Currently, there are two methods for the RW1C bit:
clear_xxx
andset_0_xxx
. The former sets the bit to 1, the latter sets it to 0.Originally, only the former existed, because I thought there was no need to write 0 in the RW1C bit. However, as pointed out in #146, there are actually situations where it is necessary to write 0 to prevent the bit from being erased, which is why the latter was added in #148.
I didn't think anything when I merged #148, but later I thought this was obviously confusing. For example, the same
clear_xxx
method exists for RW bits, but this method sets the corresponding bit to0
.Should I fix this and have the RW1C bits also have
set_xxx
/clear_xxx
methods that actually set the bits to 1/0?One problem is that the
clear_xxx
method will have the exact opposite meaning in a later version of this change, and thus must be clarified in the changelog.The text was updated successfully, but these errors were encountered: