Skip to content

Commit

Permalink
Make field setters const.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Oct 27, 2024
1 parent 6adc0a7 commit c425255
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/generate/fieldset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn render(_opts: &super::Options, ir: &IR, fs: &FieldSet, path: &str) -> Res
}
#doc
#[inline(always)]
pub fn #name_set(&mut self, n: usize, val: #field_ty) {
pub const fn #name_set(&mut self, n: usize, val: #field_ty) {
assert!(n < #len);
let offs = #off_in_reg + #offs_expr;
self.0 = (self.0 & !(#mask << offs)) | (((#to_bits) & #mask) << offs);
Expand Down Expand Up @@ -138,7 +138,7 @@ pub fn render(_opts: &super::Options, ir: &IR, fs: &FieldSet, path: &str) -> Res
}
#doc
#[inline(always)]
pub fn #name_set(&mut self, n: usize, val: #field_ty) {
pub const fn #name_set(&mut self, n: usize, val: #field_ty) {
assert!(n < #len);
#( let offs = #off_in_reg + #offs_expr;
self.0 = (self.0 & !(#mask << offs)) | (((#to_bits >> #off_in_val) & #mask) << offs); )*;
Expand All @@ -155,7 +155,7 @@ pub fn render(_opts: &super::Options, ir: &IR, fs: &FieldSet, path: &str) -> Res
}
#doc
#[inline(always)]
pub fn #name_set(&mut self, val: #field_ty) {
pub const fn #name_set(&mut self, val: #field_ty) {
#( self.0 = (self.0 & !(#mask << #off_in_reg)) | (((#to_bits >> #off_in_val) & #mask) << #off_in_reg); )*;
}
))
Expand Down

0 comments on commit c425255

Please sign in to comment.