pub struct ServerBuilder { /* private fields */ }Expand description
Implementations§
Source§impl ServerBuilder
impl ServerBuilder
Sourcepub fn runtime(self, config: RuntimeConfig) -> Self
pub fn runtime(self, config: RuntimeConfig) -> Self
Set the runtime configuration.
Sourcepub fn serve_config(self, config: Arc<ServeConfig>) -> Self
pub fn serve_config(self, config: Arc<ServeConfig>) -> Self
Set a pre-built serve configuration.
This bridges the CLI/Python configuration model. The runtime config is derived from the serve config’s limits and bind address.
Sourcepub fn bind(self, addr: SocketAddr) -> Self
pub fn bind(self, addr: SocketAddr) -> Self
Set the bind address for the listener.
This overrides the bind address from RuntimeConfig. The server will
bind to this address when start() is called.
Sourcepub fn from_listener(self, listener: TcpListener) -> Self
pub fn from_listener(self, listener: TcpListener) -> Self
Use a pre-bound TCP listener instead of binding on start.
The listener must already be bound to an address. The runtime will
take ownership of the listener after a successful start().
§Blocking/nonblocking
The listener should be in nonblocking mode (as returned by
TcpListener::bind and TcpListener::from_std).
The runtime will normalize to nonblocking if needed.
§Ownership
After start(), the runtime owns the listener. The caller must not
use the listener after passing it to the builder.
Sourcepub fn build(self) -> Result<Server, ServerError>
pub fn build(self) -> Result<Server, ServerError>
Build the server, eagerly constructing the built-in static file service when a serve configuration was supplied.
Invalid static roots therefore fail during build(), before listener
preparation or startup. The serve config must have been set via
ServerBuilder::serve_config for Server::start to be available.
Sourcepub fn static_service(
self,
root: impl AsRef<Path>,
) -> Result<Server, ServerError>
pub fn static_service( self, root: impl AsRef<Path>, ) -> Result<Server, ServerError>
Build the server with a static service rooted at the given path.
Convenience method that creates both the serve config and runtime config.