Skip to content

Commit cc512a0

Browse files
committed
Rename bit read/write methods.
set() -> set_bit() clear() -> clear_bit() is_set() -> is_bit_set() is_clear() -> is_bit_clear() Also adds these names to the list of reserved keywords along with bit and bits so that they are suffixed with an underscore if used as a variant name.
1 parent 1b9f439 commit cc512a0

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/generate.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -889,13 +889,13 @@ pub fn fields(
889889
enum_items.push(quote! {
890890
/// Returns `true` if the bit is clear (0)
891891
#[inline(always)]
892-
pub fn is_clear(&self) -> bool {
892+
pub fn is_bit_clear(&self) -> bool {
893893
!self.#bits()
894894
}
895895

896896
/// Returns `true` if the bit is set (1)
897897
#[inline(always)]
898-
pub fn is_set(&self) -> bool {
898+
pub fn is_bit_set(&self) -> bool {
899899
self.#bits()
900900
}
901901
});
@@ -1014,13 +1014,13 @@ pub fn fields(
10141014
pc_r_impl_items.push(quote! {
10151015
/// Returns `true` if the bit is clear (0)
10161016
#[inline(always)]
1017-
pub fn is_clear(&self) -> bool {
1017+
pub fn is_bit_clear(&self) -> bool {
10181018
!self.#bits()
10191019
}
10201020

10211021
/// Returns `true` if the bit is set (1)
10221022
#[inline(always)]
1023-
pub fn is_set(&self) -> bool {
1023+
pub fn is_bit_set(&self) -> bool {
10241024
self.#bits()
10251025
}
10261026
});
@@ -1246,16 +1246,18 @@ pub fn fields(
12461246
);
12471247
}
12481248
}
1249-
} else if width == 1 {
1249+
}
1250+
1251+
if width == 1 {
12501252
proxy_items.push(
12511253
quote! {
12521254
/// Sets the field bit
1253-
pub fn set(self) -> &'a mut W {
1255+
pub fn set_bit(self) -> &'a mut W {
12541256
self.bit(true)
12551257
}
12561258

12571259
/// Clears the field bit
1258-
pub fn clear(self) -> &'a mut W {
1260+
pub fn clear_bit(self) -> &'a mut W {
12591261
self.bit(false)
12601262
}
12611263
}

src/util.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ impl ToSanitizedSnakeCase for str {
9696
where,
9797
while,
9898
yield,
99+
bit_set,
100+
bit_clear,
101+
set_bit,
102+
clear_bit,
103+
bit,
104+
bits,
99105
}
100106
}
101107
}

0 commit comments

Comments
 (0)