2022-12-16
2145
#rust
Andre Bogus
148572
104
Dec 16, 2022 â‹… 7 min read

How to build a Rust API with the builder pattern

Andre Bogus Andre "llogiq" Bogus is a Rust contributor and Clippy maintainer. A musician-turned-programmer, he has worked in many fields, from voice acting and teaching, to programming and managing software projects. He enjoys learning new things and telling others about them.

Recent posts:

Rxjs Adoption Guide: Overview, Examples, And Alternatives

RxJS adoption guide: Overview, examples, and alternatives

Get to know RxJS features, benefits, and more to help you understand what it is, how it works, and why you should use it.

Emmanuel Odioko
Jul 26, 2024 â‹… 13 min read
Decoupling Monoliths Into Microservices With Feature Flags

Decoupling monoliths into microservices with feature flags

Explore how to effectively break down a monolithic application into microservices using feature flags and Flagsmith.

Kayode Adeniyi
Jul 25, 2024 â‹… 10 min read
Lots of multi-colored blue and purplish rectangles.

Animating dialog and popover elements with CSS @starting-style

Native dialog and popover elements have their own well-defined roles in modern-day frontend web development. Dialog elements are known to […]

Rahul Chhodde
Jul 24, 2024 â‹… 10 min read
Using Llama Index To Add Personal Data To Large Language Models

Using LlamaIndex to add personal data to LLMs

LlamaIndex provides tools for ingesting, processing, and implementing complex query workflows that combine data access with LLM prompting.

Ukeje Goodness
Jul 23, 2024 â‹… 5 min read
View all posts

2 Replies to "How to build a Rust API with the builder pattern"

  1. The build patterns are awkward because of the borrow checker, the complexity is obvious from articles like this. So my conclusion is actually that optional named parameters are very much needed in Rust to alleviate the creation of objects with a less heavy solution that is more efficient, easier to read and that doesn’t require the creation of intermediate objects.

    Another alternative is to make functions and methods optionally pass ownership, only if the function/method output is assigned to a variable.

  2. I disagree. First, often you can get away with having one or two methods or a plain struct to work with. The builder just ensures a nice and flexible interface while keeping open the door to later changes. Also the complexity cost is mostly paid by libraries which are usually meant to be reused, thus amortizing the investment.

Leave a Reply