-
I happen to encounter this case, some attributes are used in the building function, but not needed in the final struct. It also needs to be a reference and I'd like not to include lifetime in the final struct. |
Beta Was this translation helpful? Give feedback.
Answered by
Veetaha
Apr 17, 2025
Replies: 1 comment 1 reply
-
Hi, if you'd like to have custom fields only during the building process, then consider using a function-based builder instead of struct Example {
x: u32,
y: u32,
}
#[bon::bon]
impl Example {
#[builder]
fn new(
x: u32,
y: u32,
custom_builder_only_field: &u32,
) -> Self {
// ... use the `custom_builder_only_field` here to build the struct
// Return the final struct
Self { x, y }
}
}
Example::builder()
.x(1)
.y(2)
.custom_builder_only_field(&3)
.build(); Or I may have misunderstood your use case. Could you share some specific example of code to better demonstrate the problem? |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
inflation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, if you'd like to have custom fields only during the building process, then consider using a function-based builder instead of
derive(Builder)
:Or I may have misunderstood your use case. Could you share some specific example of code to better demonstrate the problem?