programatik29 / axum-server

High level server designed to be used with axum framework.
MIT License
177 stars 63 forks source link

Split ServerBuilder and Server structs. #34

Closed sebpuetz closed 2 years ago

sebpuetz commented 2 years ago

This takes a slightly different approach to what you suggested in #33, just wanted to get some quick feedback whether you think this would also be a good solution.

The main idea is to split up the builder from the actual server struct and bundle the server future together with the actually bound address.

programatik29 commented 2 years ago

I think Option<SocketAddr> solution that you mentioned in #33 is the best approach.

In my opinion, there is no need to introduce a Builder if it can be avoided.

sebpuetz commented 2 years ago

Your call, but this doesn't really introduce a builder, the builder is already present as the Server struct. My PR renames it and splits Server::serve() into two stages:

  1. binding the socket
  2. preparing the server and placing it in a struct

That's motivated by a cleaner separation between setup (currently done via Server::acceptor(), etc.) and runtime (currently Server::serve()). If an Ok(Server) is returned from serve(), the server has been built succesfully and can start serving connections by awaiting it.

It also helps with clarifying the API, currently it's a bit confusing because Server::bind() only configures the builder while the serve() call actually binds the socket, builds the actual server and returns the future to run it.

programatik29 commented 2 years ago

Good point. I am currently busy though. I will take a look at it later.

programatik29 commented 2 years ago

See #42.