Skip to content

Commit aef7b67

Browse files
committed
Add Default trait implementation and new method to bitmap structs
1 parent 89d2574 commit aef7b67

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

macros/src/generator.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ pub fn expand_bitmap(input: BitmapInput) -> syn::Result<TokenStream2> {
4545
}
4646

4747
#[inline]
48-
pub fn #setter_name(&mut self, value: #storage_ty) -> &mut Self {
49-
assert!(value <= #mask as #storage_ty);
48+
pub fn #setter_name(&mut self, value: #this_storage_ty) -> &mut Self {
49+
assert!(value <= #mask as #this_storage_ty);
5050
self.0 = ((self.0 & !((#mask) << #bit_index)) | (((value as #storage_ty) & #mask) << #bit_index));
5151
self
5252
}
@@ -69,9 +69,19 @@ pub fn expand_bitmap(input: BitmapInput) -> syn::Result<TokenStream2> {
6969
pub struct #name(#storage_ty);
7070

7171
impl #name {
72+
fn new(value: #storage_ty) -> Self {
73+
Self(value)
74+
}
75+
7276
#(#accessors)*
7377
}
7478

79+
impl Default for #name {
80+
fn default() -> Self {
81+
Self(0)
82+
}
83+
}
84+
7585
impl ::core::convert::From<#name> for #storage_ty {
7686
fn from(value: #name) -> Self {
7787
value.0

0 commit comments

Comments
 (0)