Closed jyn514 closed 3 years ago
Another alternative would be to not invalidate the builder in .build()
. This would require at least one public API change, as the format function is currently not required to be Clone
. I think I prefer this solution though.
@KodrAus wdyt?
Isn't this still a breaking change, no matter what approach we take (this or yours @jplatte)? I do also prefer this solution though.
Yes, would be a breaking change either way.
I personally prefer by-value builders so would be up for a new release that changed these to work that way.
I think originally we went with by-reference in the first place because you used to have to detect environment variables and yourself and pass the value through to the builder. Those cases where you conditionally interact with a builder are easier when they're by-reference, but since we have the Env
API I don't think that's the case anymore.
We should be able to always configure env_logger
in a single expression of chained builder methods.
I've created a v0.9.x branch and merged this into that. I think this can wait for a bit, maybe some other breaking changes are going to come around.
Previously,
build()
would take&mut self
and panic if called more than once. This is not ideal, especially since it wasn't documented anywhere except in the source code. This now enforces thatbuild()
is only called once by takingself
in build.Unfortunately, that meant that chains like the following no longer worked:
It would have to instead be rewritten like this:
To avoid this, I changed all the builder functions taking
&mut self -> &mut Self
to instead takeself -> Self
. That fixes the example I gave, but broke a few others:Those I just rewrote to use
Builder::new().parse(filter).build()
instead, since that seems more idiomatic.This is a breaking change.
Alternatives
self
inbuild()
and related constructors, and ask users to usebuilder.x(); builder.build()
instead