auto_builder/
lib.rs

1//! This crate provides a derive macro to implement the [builder pattern](https://en.wikipedia.org/wiki/Builder_pattern) for any struct.
2//!
3//! Deriving the `Builder` macro for a struct named `Foo` will generate a builder struct named `FooBuilder` with methods to set each field of `Foo` and a `build` method to create a `Foo` from the builder. The `build` method will fail if any fields have not been set. It returns a `Result<Foo, String>` where the `String` is an error message indicating which fields have not been set.
4//!
5//! ## Example
6//! ```
7//! use auto_builder::Builder;
8//!
9//! #[derive(Builder)]
10//! struct Foo {
11//!   bar: i32,
12//!   baz: String,
13//! }
14//!
15//! let complete_foo = FooBuilder::new().bar(42).baz("hello".to_string()).build()
16//! let incomplete_foo = FooBuilder::new().bar(42).build();
17//!
18//! assert!(complete_foo.is_ok());
19//! assert!(incomplete_foo.is_err());
20//! ```
21
22pub use auto_builder_macro::Builder;