| Crates.io | infallible-builder |
| lib.rs | infallible-builder |
| version | 0.0.1 |
| created_at | 2025-07-23 06:58:26.252059+00 |
| updated_at | 2025-07-23 08:34:26.78987+00 |
| description | Derive macro for infallible implementation of the builder pattern. |
| homepage | |
| repository | https://github.com/agirardeau/agpublic/rust/infallible-builder |
| max_upload_size | |
| id | 1764419 |
| size | 10,495 |
infallible-builderMacro crate for generating infallible Builder interfaces.
[dependencies]
infallible-builder = "0.0"
use infallible_builder::Builder;
#[derive(Default)]
#[Builder]
struct Person {
name: String,
age: i64,
birthday: Option<String>,
}
let person = Person::builder()
.name("Alice")
.age(30)
.build();
assert_eq!(person.name, "Alice");
assert_eq!(person.age, 30);
assert_eq!(person.birthday, None);
The base type must implement Default. To implement Default for structs with
non-Default fields, consider a crate like [smart-default]
(https://docs.rs/smart-default/latest/smart_default/):
use smart_default::SmartDefault;
// Non-Default type
pub enum Color { Red, Blue }
#[derive(SmartDefault)]
#[Builder]
pub struct Line {
length: i64,
#[default(Color::Red)]
color: Color,
}
Compared to other crates (e.g. [derive_builder]
(https://docs.rs/derive_builder/latest/derive_builder/index.html),
[typed-builder]
(https://docs.rs/typed-builder/latest/typed_builder/index.html)),
infallible-builder is more opinionated. It
generates builder types only with the following restrictions:
MyType::builder().build() is always
allowed.into()This has some direct benefits:
build() method is always infallible, improving ergonomicsinfallible-builder makes other opinionated choices with the goal of builders
for different base structs having consistent interfaces:
setter(into, strip_option) is configured by defaultClone fieldsIt is this crate author's opinion that builder customizability is ultimately detrimental, mostly enabling use cases where builders are not an ideal fit.
As of 0.0, this is implemented as attribute proc macro that adds
derive_builder::Builder to the annotated struct. As a result, some
#[builder()] annotations supported by derive_builder are respected, however
this behavior may change in the future.