Skip to content

Commit 76c79b2

Browse files
authored
A doc comments for with methods in builder and build() method (#62)
1 parent cdf15f9 commit 76c79b2

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

bitbybit-tests/src/bitfield_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,7 @@ fn underlying_type_is_arbitrary_array_complete() {
12261226
fn underlying_type_is_arbitrary_default() {
12271227
#[bitfield(u14, default = 0x567)]
12281228
struct Nibbles {
1229+
/// The nibbles
12291230
#[bits(0..=3, rw)]
12301231
first_nibble: u4,
12311232
}
@@ -1549,7 +1550,6 @@ fn test_noncontiguous_ranges_array_with_interleaving_and_builder() {
15491550
);
15501551
}
15511552

1552-
15531553
#[test]
15541554
fn test_getter_and_setter() {
15551555
#[bitfield(u128, default = 0)]

bitbybit/src/bitfield/codegen.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::bitfield::{with_name, setter_name, BaseDataSize, CustomType, FieldDefinition, BITCOUNT_BOOL};
1+
use crate::bitfield::{
2+
setter_name, with_name, BaseDataSize, CustomType, FieldDefinition, BITCOUNT_BOOL,
3+
};
24
use proc_macro2::{Ident, TokenStream as TokenStream2, TokenStream, TokenTree};
35
use quote::quote;
46
use std::ops::Range;
@@ -435,8 +437,10 @@ pub fn make_builder(
435437
running_mask = previous_mask | field_mask;
436438
running_mask_token_tree =
437439
syn::parse_str::<TokenTree>(format!("{:#x}", running_mask).as_str()).unwrap();
440+
let doc_comment = &field_definition.doc_comment;
438441
new_with_builder_chain.push(quote! {
439442
impl #builder_struct_name<#previous_mask_token_tree> {
443+
#(#doc_comment)*
440444
pub const fn #with_name(&self, value: #argument_type) -> #builder_struct_name<#running_mask_token_tree> {
441445
#builder_struct_name(#value_transform)
442446
}
@@ -452,6 +456,7 @@ pub fn make_builder(
452456

453457
new_with_builder_chain.push(quote! {
454458
impl #builder_struct_name<#running_mask_token_tree> {
459+
/// Builds the bitfield from the values passed into this builder
455460
pub const fn build(&self) -> #struct_name {
456461
self.0
457462
}

0 commit comments

Comments
 (0)