Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions bon-macros/src/builder/builder_gen/builder_decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,15 @@ impl super::BuilderGenCtx {
let docs = &self.builder_type.docs;
let state_var = &self.state_var;

let custom_fields_idents = self.custom_fields().map(|field| &field.ident);
let custom_fields_types = self.custom_fields().map(|field| &field.norm_ty);
let custom_fields = self.custom_fields().map(|field| {
let ident = &field.ident;
let ty = &field.norm_ty;
let doc = format!("Private builder field `{ident}` for use in custom methods.");
quote! {
#[doc = #doc]
#ident: #ty
}
});

quote! {
#[must_use = #must_use_message]
Expand Down Expand Up @@ -109,7 +116,7 @@ impl super::BuilderGenCtx {

#( #start_fn_args_fields, )*

#( #custom_fields_idents: #custom_fields_types, )*
#( #custom_fields, )*

#private_field_attrs
__unsafe_private_named: (
Expand Down
19 changes: 19 additions & 0 deletions bon-sandbox/src/docs_in_private_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ struct ExampleStruct {
#[builder(start_fn)]
start_fn: u32,

/// Docs on `field` member
#[builder(field)]
field: u32,

/// Docs on `finish_fn` member
#[builder(finish_fn)]
finish_fn: u32,
Expand All @@ -27,6 +31,10 @@ impl ExampleStruct {
#[builder(start_fn)]
start_fn: u32,

/// Docs on `field` member
#[builder(field)]
field: u32,

/// Docs on `finish_fn` member
#[builder(finish_fn)]
finish_fn: u32,
Expand All @@ -35,6 +43,7 @@ impl ExampleStruct {
regular: u32,
) {
let _ = start_fn;
let _ = field;
let _ = finish_fn;
let _ = regular;
}
Expand All @@ -47,6 +56,10 @@ impl ExampleStruct {
#[builder(start_fn)]
start_fn: u32,

/// Docs on `field` member
#[builder(field)]
field: u32,

/// Docs on `finish_fn` member
#[builder(finish_fn)]
finish_fn: u32,
Expand All @@ -56,6 +69,7 @@ impl ExampleStruct {
) {
let _ = self;
let _ = start_fn;
let _ = field;
let _ = finish_fn;
let _ = regular;
}
Expand All @@ -68,6 +82,10 @@ const fn example_function(
#[builder(start_fn)]
start_fn: u32,

/// Docs on `field` member
#[builder(field)]
field: u32,

/// Docs on `finish_fn` member
#[builder(finish_fn)]
finish_fn: u32,
Expand All @@ -76,6 +94,7 @@ const fn example_function(
regular: u32,
) {
let _ = start_fn;
let _ = field;
let _ = finish_fn;
let _ = regular;
}
Loading