pub struct MulticoreServer<Factory> { /* private fields */ }Expand description
Thread-per-core launcher with one compiled, non-Send app per worker.
The factory runs lazily once on every worker. Requests execute as local futures, preserving thread-local handlers and DI values.
Implementations§
Source§impl<Factory> MulticoreServer<Factory>
impl<Factory> MulticoreServer<Factory>
pub fn new(workers: NonZeroUsize, factory: Factory) -> Self
pub const fn with_max_body_bytes(self, max_body_bytes: usize) -> Self
pub const fn with_limits(self, limits: ServerLimits) -> Self
Sourcepub const fn with_request_timeout(self, timeout: Duration) -> Self
pub const fn with_request_timeout(self, timeout: Duration) -> Self
Sets a wall-clock limit for provider, hook, and handler execution.
Sourcepub fn with_openapi(self, config: OpenApiConfig) -> Self
pub fn with_openapi(self, config: OpenApiConfig) -> Self
Mounts the same precompiled OpenAPI assets in every worker-local app.
Sourcepub fn with_middleware_factory<Middleware>(self, middleware: Middleware) -> Self
pub fn with_middleware_factory<Middleware>(self, middleware: Middleware) -> Self
Builds worker-local middleware once per worker, in registration order.
Middleware is !Send, so it cannot be shared across workers. The
factory runs on each worker thread and its layers stay thread-local,
exactly like the compiled app produced by the application factory.
Sourcepub const fn with_max_connections(
self,
connections: Option<NonZeroUsize>,
) -> Self
pub const fn with_max_connections( self, connections: Option<NonZeroUsize>, ) -> Self
Bounds concurrently served connections. None accepts without a cap.
A connection accepted while the cap is reached is closed immediately instead of being dispatched to a worker.
Sourcepub const fn with_tcp_nodelay(self, nodelay: bool) -> Self
pub const fn with_tcp_nodelay(self, nodelay: bool) -> Self
Enables or disables TCP_NODELAY on accepted sockets. Enabled by
default so a small response is not delayed by Nagle’s algorithm.
Sourcepub fn serve(self, address: impl ToSocketAddrs) -> Result<()>
pub fn serve(self, address: impl ToSocketAddrs) -> Result<()>
Runs until the listener fails or the process stops.
Every worker’s app is compiled and started before the first connection is accepted, so a failing startup hook refuses to boot instead of silently dropping connections.
§Errors
Returns an I/O error when binding, worker startup, accepting, or dispatching fails.
Sourcepub fn serve_gracefully(
self,
address: impl ToSocketAddrs,
shutdown: ShutdownSignal,
drain_timeout: Duration,
) -> Result<()>
pub fn serve_gracefully( self, address: impl ToSocketAddrs, shutdown: ShutdownSignal, drain_timeout: Duration, ) -> Result<()>
Stops accepting after shutdown, asks keep-alive connections to close
after the current response, and drains active work.
§Errors
Returns an I/O error when binding, worker startup, accepting, or dispatching fails.
Auto Trait Implementations§
impl<Factory> !RefUnwindSafe for MulticoreServer<Factory>
impl<Factory> !UnwindSafe for MulticoreServer<Factory>
impl<Factory> Freeze for MulticoreServer<Factory>where
Factory: Freeze,
impl<Factory> Send for MulticoreServer<Factory>where
Factory: Send,
impl<Factory> Sync for MulticoreServer<Factory>where
Factory: Sync,
impl<Factory> Unpin for MulticoreServer<Factory>where
Factory: Unpin,
impl<Factory> UnsafeUnpin for MulticoreServer<Factory>where
Factory: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BackgroundExt for T
impl<T> BackgroundExt for T
fn background(self, task: BackgroundTask) -> Background<Self>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more