@@ -152,6 +152,19 @@ impl Server {
152152 Self { config }
153153 }
154154
155+ /// Initializes the server and starts serving.
156+ ///
157+ /// Equivalent to calling [`Server::initialize`] followed by
158+ /// [`InitializedServer::serve`].
159+ pub async fn run ( self ) -> Result < ( ) > {
160+ self . initialize ( ) . await ?. serve ( ) . await
161+ }
162+
163+ /// Initializes the server's internal state, background task(s), and
164+ /// listening socket, returning an [`InitializedServer`]. To actually begin
165+ /// serving, call [`InitializedServer::serve`].
166+ ///
167+ /// Useful for tests that need full initialization before running.
155168 pub async fn initialize ( self ) -> Result < InitializedServer > {
156169 let addr = self
157170 . config
@@ -218,12 +231,9 @@ impl Server {
218231 shutdown : self . config . shutdown ,
219232 } )
220233 }
221-
222- pub async fn run ( self ) -> Result < ( ) > {
223- self . initialize ( ) . await ?. serve ( ) . await
224- }
225234}
226235
236+ /// Represents an initialized warg registry server.
227237pub struct InitializedServer {
228238 listener : TcpListener ,
229239 router : Router ,
@@ -232,10 +242,14 @@ pub struct InitializedServer {
232242}
233243
234244impl InitializedServer {
245+ /// Returns the listening address of the server. If a random listening
246+ /// port was requested (i.e. `:0`), this returns the actual bound port.
235247 pub fn local_addr ( & self ) -> std:: io:: Result < SocketAddr > {
236248 self . listener . local_addr ( )
237249 }
238250
251+ /// Serves the server's services. On server shutdown, awaits completion of
252+ /// background task(s) before returning.
239253 pub async fn serve ( self ) -> Result < ( ) > {
240254 let addr = self . local_addr ( ) ?;
241255
0 commit comments