Skip to main content

Serve

Struct Serve 

Source
pub struct Serve<L, M, S, B, E = TokioExecutor> { /* private fields */ }
Expand description

Future returned by serve.

Implementations§

Source§

impl<L, M, S, B, E> Serve<L, M, S, B, E>
where L: Listener,

Source

pub fn with_graceful_shutdown<F>( self, signal: F, ) -> WithGracefulShutdown<L, M, S, F, B, E>
where F: Future<Output = ()> + Send + 'static,

Prepares a server to handle graceful shutdown when the provided future completes.

§Example
use axum::{Router, routing::get};

let router = Router::new().route("/", get(|| async { "Hello, World!" }));

let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, router)
    .with_graceful_shutdown(shutdown_signal())
    .await;

async fn shutdown_signal() {
    // ...
}
§Return Value

Similarly to serve, although this future resolves to io::Result<()>, it will never error. It returns Ok(()) only after the signal future completes.

Source

pub fn local_addr(&self) -> Result<<L as Listener>::Addr, Error>

Returns the local address this server is bound to.

Source

pub fn connection_lifetime_limits( self, limits: ConnectionLifetimeLimits, ) -> Serve<L, M, S, B, E>

Apply per-connection ConnectionLifetimeLimits, bounding the lifetime of individual connections.

This is useful for forcing clients to rotate connections — see ConnectionLifetimeLimits for details and an example.

This method can be called before or after with_graceful_shutdown and with_executor.

Source

pub fn with_executor<E2>(self, executor: E2) -> Serve<L, M, S, B, E2>
where E2: Executor,

Provide a custom Executor to use for spawning connection tasks and hyper’s internal tasks (e.g. HTTP/2).

The default is TokioExecutor. See the Executor docs for how to implement a custom one.

This method can be called before or after with_graceful_shutdown.

§Example
use axum::{Router, routing::get, serve::Executor};
let router = Router::new().route("/", get(|| async { "Hello, World!" }));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();

axum::serve(listener, router)
    .with_executor(MyExecutor)
    .await;

Trait Implementations§

Source§

impl<L, M, S, B, E> Debug for Serve<L, M, S, B, E>
where L: Debug + 'static, M: Debug, E: Debug,

Source§

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

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

impl<L, M, S, B, E> IntoFuture for Serve<L, M, S, B, E>
where L: Listener, <L as Listener>::Addr: Debug, M: for<'a> Service<IncomingStream<'a, L>, Error = !, Response = S> + Send + 'static, <M as Service<IncomingStream<'a, L>>>::Future: for<'a> Send, S: Service<Request<Body>, Response = Response<B>, Error = !> + Clone + Send + 'static, <S as Service<Request<Body>>>::Future: Send, B: Body + Send + 'static, <B as Body>::Data: Send, <B as Body>::Error: Into<Box<dyn Error + Send + Sync>>, E: Executor,

Source§

type Output = !

The output that the future will produce on completion.
Source§

type IntoFuture = ServeFuture

Which kind of future are we turning this into?
Source§

fn into_future(self) -> <Serve<L, M, S, B, E> as IntoFuture>::IntoFuture

Creates a future from a value. Read more

Auto Trait Implementations§

§

impl<L, M, S, B, E> Freeze for Serve<L, M, S, B, E>
where L: Freeze, M: Freeze, E: Freeze,

§

impl<L, M, S, B, E> RefUnwindSafe for Serve<L, M, S, B, E>

§

impl<L, M, S, B, E> Send for Serve<L, M, S, B, E>
where L: Send, M: Send, E: Send,

§

impl<L, M, S, B, E> Sync for Serve<L, M, S, B, E>
where L: Sync, M: Sync, E: Sync,

§

impl<L, M, S, B, E> Unpin for Serve<L, M, S, B, E>
where L: Unpin, M: Unpin, E: Unpin,

§

impl<L, M, S, B, E> UnsafeUnpin for Serve<L, M, S, B, E>

§

impl<L, M, S, B, E> UnwindSafe for Serve<L, M, S, B, E>
where L: UnwindSafe, M: UnwindSafe, E: UnwindSafe,

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.

§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

§

impl<T> Instrument for T

§

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

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

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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