Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement non-failing builders for Request, Response and Uri. #483

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

kaj
Copy link

@kaj kaj commented Apr 28, 2021

Fixes #330. Replaces #442 , #448 , and #454 .

Creating a Request, Response, or Uri with the builder pattern should not require handling errors unless opting in by using a try_-method (which returns a Result<Builder>, not a Builder with an internal error state).

This is really a breaking change to the Builders, but rather than suggesting a breaking change directly, I introduce alternatives named Builder2. If this is accepted, the original Builder is deprecated, and in a later release Builder2 can be renamed back to Builder.

The new uri::Builder2 is generic on its contents, which starts out as the empty type (). The parts Scheme, Authority and PathAndQuery can be added in any combination, and the build method is implemented for valid combinations only. Looking at the generated documentation for uri::Builder2, it gets a bit repetitive, as the property and a try_property method for each of the three properties is repeated for each of the eight variants of the Builder2, and a build method for four of them.

kaj added 8 commits April 28, 2021 18:50
Fixes hyperium#330.  Creating a Response with the builder pattern should not
require handling errors unless opting in by using a `try_`-method
(which returns a `Result<Builder2>`, not a `Builder2` with an interal
error state).

This is really a breaking change to `response::Builder`, but rather
than suggstig a breaking change directly, I introduce an alternative
`response::Builder2`.  If this is liked, the original `Builder` can be
deprecated, and in a later release `Builder2` can be renamed back to
`Builder`.
If this change is accpted, the old Builder should be deprecated
directly, so the new Builder2 can take its place as soon as
semver allows.
Try to make rustc 1.39.0 happy.
Fixes one part of hyperium#330.  This makes it possible to create an `Uri`
using the builder pattern without hanlding errors.

This is really a breaking change to `uri::Builder`, but rather than
suggesting a breaking change directly, I introduce an alternative
`uri::Builder2`. If this is accepted, the original Builder is
deprecated, and in a later release Builder2 can be renamed back to
Builder.

The new `Builder2` is generic on its contents, which starts out as the
empty type `()`.  The parts `Scheme`, `Authority` and `PathAndQuery`
can be added in any combination, and the `build` method is implemented
for valid combinations only.
Fixes one part of hyperium#330. Creating a `Request` with the builder pattern
should not require handling errors unless opting in by using a
`try_`-method (which returns a `Result<Builder2>`, not a `Builder2`
with an internal error state).

This is really a breaking change to `request::Builder`, but rather
than suggesting a breaking change directly, I introduce an alternative
`response::Builder2`. If this is accepted, the original
`response::Builder` is deprecated, and in a later release `Builder2`
can be renamed back to `Builder`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace error-returning builders with typestate-based builders
1 participant