Implement Builder Pattern #840
melatron
started this conversation in
Features / Enhancements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In this library, both in the Client and the bindings, there are quite a few builder patterns. This leads to a ton of boilerplate code;
A recommendation to reduce the overall size of the codebase would be to use a macro to implement the builders instead. Common solutions already exist in the form of libraries such as
derive_builder
ortyped_builder
. Other than the code size, the largest issue with builders in Rust is with regards to situations where you have runtime configuration. If you have any kind of configuration at runtime with these builder if statements then a consuming builder is a big pain to use because you'll constantly have to re-assign variables.The init struct pattern is another alternative worth exploring in cases where your code may not need to directly build to something explicit. It also gives you the ability to avoid position arguments which general increases code readability in cases where you've got a lot of parameters.
Beta Was this translation helpful? Give feedback.
All reactions