Skip to content

Commit

Permalink
A doc comments for with methods in builder and build() method (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
danlehmann authored Dec 13, 2024
1 parent cdf15f9 commit 76c79b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bitbybit-tests/src/bitfield_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,7 @@ fn underlying_type_is_arbitrary_array_complete() {
fn underlying_type_is_arbitrary_default() {
#[bitfield(u14, default = 0x567)]
struct Nibbles {
/// The nibbles
#[bits(0..=3, rw)]
first_nibble: u4,
}
Expand Down Expand Up @@ -1549,7 +1550,6 @@ fn test_noncontiguous_ranges_array_with_interleaving_and_builder() {
);
}


#[test]
fn test_getter_and_setter() {
#[bitfield(u128, default = 0)]
Expand Down
7 changes: 6 additions & 1 deletion bitbybit/src/bitfield/codegen.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::bitfield::{with_name, setter_name, BaseDataSize, CustomType, FieldDefinition, BITCOUNT_BOOL};
use crate::bitfield::{
setter_name, with_name, BaseDataSize, CustomType, FieldDefinition, BITCOUNT_BOOL,
};
use proc_macro2::{Ident, TokenStream as TokenStream2, TokenStream, TokenTree};
use quote::quote;
use std::ops::Range;
Expand Down Expand Up @@ -435,8 +437,10 @@ pub fn make_builder(
running_mask = previous_mask | field_mask;
running_mask_token_tree =
syn::parse_str::<TokenTree>(format!("{:#x}", running_mask).as_str()).unwrap();
let doc_comment = &field_definition.doc_comment;
new_with_builder_chain.push(quote! {
impl #builder_struct_name<#previous_mask_token_tree> {
#(#doc_comment)*
pub const fn #with_name(&self, value: #argument_type) -> #builder_struct_name<#running_mask_token_tree> {
#builder_struct_name(#value_transform)
}
Expand All @@ -452,6 +456,7 @@ pub fn make_builder(

new_with_builder_chain.push(quote! {
impl #builder_struct_name<#running_mask_token_tree> {
/// Builds the bitfield from the values passed into this builder
pub const fn build(&self) -> #struct_name {
self.0
}
Expand Down

0 comments on commit 76c79b2

Please sign in to comment.