All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
- Add
#[builder(setter(strip_option(fallback = field_opt)))]
to add a fallback unstripped method to the builder struct. - Add
#[builder(setter(strip_bool(fallback = field_bool)))]
to add a fallback setter that takes thebool
value to the builder struct.
- Fix mutators for generic fields (see issue #149)
- Use fields' doc comments for the setters.
- Also add the licenses to the macro crate.
- Add
#[allow(clippy::no_effect_underscore_binding)]
to generated methods that need to destructure intermediate builder state. - Use a proper
OR
syntax for the dual license.
?Sized
generic parameters are now supported.
- Internal refactor of attribute parsing - results in better error messages and easier proces for adding new settings.
#[builder(mutators(...))]
to generate functions on builder to mutate fields#[builder(via_mutator)]
on fields to allow defining fields initialized during::builder()
for use withmutators
mutable_during_default_resolution
to allowdefault
expression mutate previous fields.
- Add support for paths with angle brackets (see PR #122 )
- Use generics with the constructor in
build
method (see issue #118)
- Add
#[allow(clippy::exhaustive_enums)]
to generated empty enums used for error "reporting" (see issue #112) - Add
#[automatically_derived]
to generatedimpl
s (see issue #114) - Add
#[allow(clippy::used_underscore_binding)]
to build method and setter methods (see issue #113)
#[builder(crate_module_path = ...)]
for overcoming cases where the derive macro is used in another crate's macro (see issue #109)
- Fix const generics generating "empty" entries in some lists, resulting in consecutive commas (see issue #106)
- no-std build.
- [BREAKING] Split the derive macro out to a separate procmacro crate. This is considered a breaking change because reexporting and/or renmaing the crate can now prevent the generated code from finding the types it needs (see issue #101)
- Marking a field as
#[deprecated]
now behaves properly -TypedBuilder
generated code itself does trigger the deprecation warning, and instead the setter for that field now does. - The "fake"
build
method when required fields are not provided now returns the never type ("!
"). Refer to PR #97 for more thorough explanation.
- Support for setter method prefixes and suffixes
#[builder(field_defaults(setter(prefix = "...", suffix = "...")))]
. This either prepends or appends the provided string to the setter method. This allows method names like:set_x()
,with_y()
, orset_z_value()
.
build_method(into)
andbuild_method(into = ...)
.
y
- [BREAKING] Builder state parameter moved to the end of the generated builder type's parameters list.
- Generated builder type's builder state parameter now defaults to tuple of empty tuples. This means the empty builder, where no parameter is yet set.
#[builder(build_method(...))]
now affects the fakebuild
method that's generated to add information to the compiler error.
- [BREAKING]
builder_method_doc = "..."
,builder_type_doc = "..."
andbuild_method_doc = "..."
are replaced withbuilder_method(doc = "...")
,builder_type(doc = "...")
andbuild_method(doc = "...")
.
build_method(...)
now has adoc
field.builder_method(...)
andbuilder_type(...)
, which are structured similarly tobuild_method(...)
.
#[builder(build_method(vis="pub", name=build))]
for customizing visibility and fn name of the final build method (the default visibility ispub
, and default build name isbuild
)
#[builder(setter(strip_bool))]
for making zero arguments setters forbool
fields that just set them totrue
(thedefault
automatically becomesfalse
)
- Add
extern crate proc_macro;
to solve some weird problem (#57) - Use unambiguous
::
prefixed absolute paths in generated code.
- Builder type implements
Clone
when all set fields support clone. #[builder(setter(transform = ...))]
attribute for running a transform on a setter's argument to convert them to the field's type.
- Fix code generation for raw identifiers.
- Upgraded the Rust edition to 2018.
#[field_defaults(...)]
attribute for settings default attributes for all the fields.
- Fix lifetime bounds erroneously preserved in phantom generics.
- Brought back
default_code
, because it needed to resolve conflict with other custom derive proc-macro crates that try to parse[#builder(default = ...)]
attribute in order to decide if they are relevant to them - and fail because the expect them to be simple literals.
- Ability to use
into
andstrip_option
simultaneously for a field.
- [BREAKING] Specifying
skip
twice in the samebuilder(setter(...))
is no longer supported. Then again, if you were doing that you probably deserve having your code broken.
- Prevent Clippy from warning about the
panic!()
in the faux build method.
- [BREAKING] Move
doc
andskip
into a subsetting namedsetter(...)
. This means that#[builder(doc = "...")]
, for example, should now be written as#[builder(setter(doc = "..."))]
. - [BREAKING] Setter arguments by default are no longer automatically
converted to the target type with
into()
. If you want to automatically convert them, use#[builder(setter(into))]
. This new default enables rustc inference for generic types and proper integer literal type detection. - Improve build errors for incomplete
.build()
and repeated setters, by creating faux methods with deprecation warnings.
#[builder(setter(strip_option))]
for making setters forOption
fields automatically wrap the argument withSome(...)
. Note that this is a weaker conversion than#[builder(setter(into))]
, and thus can still support type inference and integer literal type detection.
- [BREAKING] Removed the
default_code
setting (#[builder(default_code = "...")]
) because it is no longer required now that Rust andsyn
support arbitrary expressions in attributes.
- [BREAKING] now state types are placed before original generic types.
Previously, all state types are appended to generic arguments. For example,
Foo<'a, X, Y>
yieldsFooBuilder<'a, X, Y, ((), ())>
previously, and now it becomesFooBuilder<'a, ((), ()), X, Y, >.
. This change fix compiler error for struct with default type likeFoo<'a, X, Y=Bar>
. Rust only allow type parameters with a default to be trailing.
#![no_std]
is now supported out of the box. (You don't need to opt into any features, it just works.)- [BREAKING] a
default_code
expression can now refer to the values of earlier fields by name (This is extremely unlikely to break your code, but could in theory due to shadowing) #[builder(skip)]
on fields, to not provide a method to set that field.- Control of documentation:
#[builder(doc = "…")]
on fields, to document the field's method on the builder. Unlike#[doc]
, you can currently only have one value rather than one attribute per line; but that's not a big deal since you don't get to use the///
sugar anyway. Just use a multiline string.#[builder(doc, builder_method_doc = "…", builder_type_doc = "…", build_method_doc = "…")]
on structs:doc
unhides the builder type from the documentation.builder_method_doc = "…"
replaces the default documentation that will be generated for the builder() method of the type for which the builder is being generated.builder_type_doc = "…"
replaces the default documentation that will be generated for the builder type. Impliesdoc
.build_method_doc = "…"
replaces the default documentation that will be generated for the build() method of the builder type. Impliesdoc
.
- [BREAKING] Renamed the generated builder type from
TypedBuilder_BuilderFor_Foo
toFooBuilder
, for improved ergonomics, especially when you enable documentation of the builder type.- Generic identifiers were also changed, from
TypedBuilder_genericType_x
to__x
. This is still expected to avoid all name collisions, but is easier to read in the builder type docs if you enable them. - Renamed the conversion helper trait for documentation purposes
(
TypedBuilder_conversionHelperTrait_Foo
toFooBuilder_Optional
), and its method name for simpler code.
- Generic identifiers were also changed, from
- [BREAKING]
default_code
is now lazily evaluated instead of eagerly; any side-effects that there might have been will no longer occur. As is usual in this release, this is very unlikely to affect you. - The restriction that there be only one
#[builder]
attribute per field has been lifted. You can now write#[builder(skip)] #[builder(default)]
instead of#[builder(skip, default)]
if you want to. As was already the case, latest definition wins. - [BREAKING] Use a single generic parameter to represent the builder type's state (see issue #21). Previously we would use a parameter for each field.
- Move to dual license - MIT/Apache-2.0. Previously this project was just MIT.
#[builder(default_code = "...")]
syntax for defaults that cannot be parsed as attributes no matter what.
- Move the docs from the crate to the custom derive proc macro.
- Upgraded
syn
version to support Rust 2018. - [BREAKING] Changed attribute style to
#[builder(...)]
:#[default]
->#[builder(default)]
#[default=...]
->#[builder(default=...)]
- [BREAKING]
default
no longer needs to be a string.- But you need to change your code anyways because the attribute style was changed.
- Allow missing docs in structs that derive
TypedBuilder
.
- Custom derive for generating the builder pattern.
- All setters are accepting
Into
values. - Compile time verification that all fields are set before calling
.build()
. - Compile time verification that no field is set more than once.
- Ability to annotate fields with
#[default]
to make them optional and specify a default value when the user does not set them. - Generates simple documentation for the
.builder()
method.