idanarye/rust-typed-builder

How to implement Default with a function?

Closed this issue · 2 comments

Hi, is it possible to set default that is more complex when using this library? For example, I have a struct that implement default like this:

impl Default for RsCantoneseConfig {
    fn default() -> Self {
        let mut model_path = std::env::temp_dir();
        model_path.push(constant::MODEL_PATH);

        RsCantoneseConfig {
            model_path,
        }
    }
}
#[derive(typed_builder::TypedBuilder)]
struct RsCantoneseConfig {
    #[builder(default = {
        let mut model_path = std::env::temp_dir();
        model_path.push(constant::MODEL_PATH);
        model_path
    })]
    model_path: PathBuf,
}

Perfect thanks!