Skip to main content

ServerHandle

Struct ServerHandle 

Source
pub struct ServerHandle { /* private fields */ }
Expand description

Handle to a running server instance.

This type is experimental and its API may change without notice.

The handle allows the caller to:

Dropping the handle triggers graceful shutdown — the server stops accepting new connections and drains in-flight requests.

Implementations§

Source§

impl ServerHandle

Source

pub fn local_addr(&self) -> SocketAddr

Returns the address the server is listening on.

Useful when binding to port 0 to discover the actual port.

Source

pub fn state(&self) -> LifecycleState

Returns the current lifecycle state.

Source

pub async fn ready(&self) -> Result<(), ServerError>

Wait for the server to be ready to accept connections.

This returns once the listener is bound and the accept loop has been polled. After this returns, the server will accept new connections.

If the server fails during startup, this returns an error.

§State behavior
  • Running: immediate success (already ready)
  • Starting: waits for transition to Running or Failed
  • Failed: returns startup error
  • Created: returns not-started error
  • Draining/Stopped: returns not-running error
Source

pub fn shutdown(&self)

Trigger graceful shutdown.

The server will stop accepting new connections and wait for in-flight requests to complete (up to the configured grace period).

Multiple calls are idempotent — only the first call has an effect.

Source

pub async fn force_shutdown( self, deadline: Duration, ) -> Result<ShutdownResult, ServerError>

Trigger forced shutdown with a deadline.

Sends the shutdown signal and waits for the server to stop. If the server does not stop within deadline, the accept task is aborted and the server is marked stopped.

Returns the ShutdownResult indicating how the shutdown completed.

Source

pub async fn wait(self) -> Result<ShutdownResult, ServerError>

Wait for the server to finish.

This consumes the handle. If the server is still running, triggers graceful shutdown first, then waits for all connections to drain. Returns the ShutdownResult indicating how the shutdown completed.

Trait Implementations§

Source§

impl Debug for ServerHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for ServerHandle

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

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> 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<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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, 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.