Closed TedDriggs closed 3 years ago
Alternatively a simpler solution is possible. Just allow to make build()
method and error type private.
#[derive(Builder)]
#[builder(error(private))]
#[builder(build_fn(name = "build_impl", private))]
struct Lorem {
pub ipsum: u8,
}
impl LoremBuilder {
pub fn build(&self) -> Result<Lorem, CustomError> {
self.build_impl()
.map_err(|private_lorem_builder_error| CustomError::new(... private_lorem_builder_error...))
}
}
Crates may already have an error into which they'd like to feed builder failures. Add
#[builder(build_fn(error = "..."))]
to allow specifying that, and document the contract for that custom error type.