Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Currently,
serve
andwith_graceful_shutdown
do not document anything about their return values. The type system says that both returnio::Result<()>
, but in context it is not obvious how this should be interpreted, and the user is left to guess.As it happens, in the current implementation it is impossible for
serve
to ever return, and likewisewith_graceful_shutdown
will never error. It seems unlikely to me that we would want to change this behaviour, and so it would be useful if people could instead rely on it.Alternatively, if we do plan on allowing
serve
to return or error in future, this fact should be documented, and it should be specified what action the user is expected to take in that scenario (quit the app? restart the server?).Solution
This commit adds to the documentation a guarantee that
Serve
andWithGracefulShutdown
are both infallible, thatServe
never completes successfully, and thatWithGracefulShutdown
only completes after its signal future has finished.It refactors the implementations of both to guarantee this fact in the type system as well.
Future Possibilities
Of course, it would be nice if
serve
would instead return!
andwith_graceful_shutdown
()
, but that will have to wait for a breaking change.