Skip to content
Discussion options

You must be logged in to vote

Hi! If you have a complex async computation for an interdependent field, you might need to use a more flexible function-based syntax for the builder in this case. So it'll look like this:

struct Blah {
    generated_async_using_x: bool,
    x: Option<bool>,
}

#[bon::bon]
impl Blah {
    #[builder]
    async fn new(x: Option<bool>) -> Self {
        Self {
            // can be any async/await expression here
            generated_async_using_x: x.unwrap_or_default(),
            x,
        }
    }
}

async fn example() {
    let _blah = Blah::builder().x(true).build().await;
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@fiadliel
Comment options

Answer selected by fiadliel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants