pub struct OmbracServer { /* private fields */ }Expand description
OmbracServer provides a simple, easy-to-use API for starting and managing the ombrac server using QUIC transport.
This struct hides all transport-specific implementation details and provides a clean interface for external users.
§Example
use ombrac_server::{OmbracServer, ServiceConfig};
use std::sync::Arc;
let config = Arc::new(ServiceConfig {
secret: "my-secret".to_string(),
listen: "0.0.0.0:8080".parse()?,
transport: Default::default(),
connection: Default::default(),
logging: Default::default(),
});
let server = OmbracServer::build(config).await?;
// ... use server ...
server.shutdown().await;Implementations§
Source§impl OmbracServer
impl OmbracServer
Sourcepub async fn build(config: Arc<ServiceConfig>) -> Result<Self>
pub async fn build(config: Arc<ServiceConfig>) -> Result<Self>
Builds a new server instance from the configuration.
This method:
- Creates a QUIC server from the transport configuration
- Sets up connection validation using the secret
- Spawns the accept loop in a background task
- Returns an OmbracServer handle for lifecycle management
§Arguments
config- The service configuration containing transport, connection, and secret settings
§Returns
A configured OmbracServer instance ready to accept connections, or an error
if configuration is invalid or server setup fails.
Sourcepub fn metrics(&self) -> Metrics
pub fn metrics(&self) -> Metrics
Returns a clone-able handle to runtime metrics for this server.
Callers can snapshot or read individual counters at any time:
server.metrics().snapshot().
Sourcepub async fn shutdown(self)
pub async fn shutdown(self)
Gracefully shuts down the server.
This method will:
- Send a shutdown signal to stop accepting new connections
- Wait for the accept loop to finish gracefully
- Wait for existing connections to close
§Example
server.shutdown().await;Sourcepub async fn shutdown_with_drain(self, drain_timeout: Duration) -> bool
pub async fn shutdown_with_drain(self, drain_timeout: Duration) -> bool
Stops accepting new connections, then waits up to drain_timeout for
in-flight streams to close naturally before returning.
Returns true if all streams drained within the timeout, false if
the timeout elapsed with active streams still in flight. In the latter
case, those streams’ tasks will keep running until their underlying
QUIC connection closes (typically via idle timeout) — they are not
hard-cancelled by this call.
Use this for rolling restarts where you want existing client requests to complete before the process exits.