Skip to main content

MulticoreServer

Struct MulticoreServer 

Source
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>
where Factory: Fn() -> ExecutableApp + Send + Sync + 'static,

Source

pub fn new(workers: NonZeroUsize, factory: Factory) -> Self

Source

pub const fn with_max_body_bytes(self, max_body_bytes: usize) -> Self

Source

pub const fn with_limits(self, limits: ServerLimits) -> Self

Source

pub const fn with_request_timeout(self, timeout: Duration) -> Self

Sets a wall-clock limit for provider, hook, and handler execution.

Source

pub fn with_openapi(self, config: OpenApiConfig) -> Self

Mounts the same precompiled OpenAPI assets in every worker-local app.

Source

pub fn with_middleware_factory<Middleware>(self, middleware: Middleware) -> Self
where Middleware: Fn() -> Vec<Rc<dyn HttpMiddleware>> + Send + Sync + 'static,

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.

Source

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.

Source

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.

Source

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.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> BackgroundExt for T

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ResponseExt for T

Source§

fn header( self, name: impl Into<String>, value: impl Into<String>, ) -> WithHeaders<Self>

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more