pub struct Server(/* private fields */);
Expand description
The primary server structure that provides a thread-safe interface to the server’s state.
This struct acts as a public-facing wrapper around an Arc<RwLock<ServerInner>>
.
It allows multiple parts of the application to safely share and modify the server’s
configuration and state across different threads and asynchronous tasks.
Implementations§
Source§impl Server
Represents the server, providing methods to configure and run it.
impl Server
Represents the server, providing methods to configure and run it.
This struct wraps the ServerInner
configuration and routing logic,
offering a high-level API for setting up the HTTP and WebSocket server.
Sourcepub async fn from(config: ServerConfig) -> Self
pub async fn from(config: ServerConfig) -> Self
Sourcepub async fn handle_hook(&self, hook: HookMacro)
pub async fn handle_hook(&self, hook: HookMacro)
Handle a given hook macro asynchronously.
This function dispatches the provided HookMacro
to the appropriate
internal handler based on its HookType
. Supported hook types include
panic hooks, disable HTTP/WS hooks, connected hooks, pre-upgrade hooks,
request/response middleware, and routes.
§Arguments
HookMacro
: TheHookMacro
instance containing theHookType
and its handler.
Sourcepub async fn config_str<C: ToString>(&self, config_str: C) -> &Self
pub async fn config_str<C: ToString>(&self, config_str: C) -> &Self
Sourcepub async fn config(&self, config: ServerConfig) -> &Self
pub async fn config(&self, config: ServerConfig) -> &Self
Sourcepub async fn panic_hook<F, Fut>(&self, hook: F) -> &Self
pub async fn panic_hook<F, Fut>(&self, hook: F) -> &Self
Sourcepub async fn request_middleware<F, Fut>(&self, hook: F) -> &Self
pub async fn request_middleware<F, Fut>(&self, hook: F) -> &Self
Sourcepub async fn response_middleware<F, Fut>(&self, hook: F) -> &Self
pub async fn response_middleware<F, Fut>(&self, hook: F) -> &Self
Sourcepub fn format_host_port<H: ToString>(host: H, port: usize) -> String
pub fn format_host_port<H: ToString>(host: H, port: usize) -> String
Sourcepub async fn run(&self) -> ServerResult<ServerHook>
pub async fn run(&self) -> ServerResult<ServerHook>
Starts the server, binds to the configured address, and begins listening for connections.
This is the main entry point to launch the server. It will initialize the panic hook, create a TCP listener, and then enter the connection acceptance loop in a background task.
§Returns
Returns a ServerResult
containing a shutdown function on success.
Calling this function will shut down the server by aborting its main task.
Returns an error if the server fails to start.
Trait Implementations§
Source§impl PartialEq for Server
Implements the PartialEq
trait for Server
.
impl PartialEq for Server
Implements the PartialEq
trait for Server
.
This allows for comparing two Server
instances for equality.
impl Eq for Server
Implements the Eq
trait for Server
.
This indicates that Server
has a total equality relation.