Struct HandlerService

struct HandlerService<H, T, S> { ... }

An adapter that makes a Handler into a Service.

Created with Handler::with_state or HandlerWithoutStateExt::into_service.

Implementations

impl<H, T, S> HandlerService<H, T, S>

fn state(self: &Self) -> &S

Get a reference to the state.

fn into_make_service(self: Self) -> IntoMakeService<HandlerService<H, T, S>>

Convert the handler into a MakeService.

This allows you to serve a single handler if you don't need any routing:

use axum::{
    handler::Handler,
    extract::State,
    http::{Uri, Method},
    response::IntoResponse,
};
use std::net::SocketAddr;

#[derive(Clone)]
struct AppState {}

async fn handler(State(state): State<AppState>) {
    // ...
}

let app = handler.with_state(AppState {});

# async {
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app.into_make_service()).await.unwrap();
# };
fn into_make_service_with_connect_info<C>(self: Self) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, S>, C>

Convert the handler into a MakeService which stores information about the incoming connection.

See Router::into_make_service_with_connect_info for more details.

use axum::{
    handler::Handler,
    response::IntoResponse,
    extract::{ConnectInfo, State},
};
use std::net::SocketAddr;

#[derive(Clone)]
struct AppState {};

async fn handler(
    ConnectInfo(addr): ConnectInfo<SocketAddr>,
    State(state): State<AppState>,
) -> String {
    format!("Hello {addr}")
}

let app = handler.with_state(AppState {});

# async {
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(
    listener,
    app.into_make_service_with_connect_info::<SocketAddr>(),
).await.unwrap();
# };

impl<H, T, S> Clone for HandlerService<H, T, S>

fn clone(self: &Self) -> Self

impl<H, T, S> Debug for HandlerService<H, T, S>

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

impl<H, T, S> Freeze for HandlerService<H, T, S>

impl<H, T, S> RefUnwindSafe for HandlerService<H, T, S>

impl<H, T, S> Send for HandlerService<H, T, S>

impl<H, T, S> Sync for HandlerService<H, T, S>

impl<H, T, S> Unpin for HandlerService<H, T, S>

impl<H, T, S> UnsafeUnpin for HandlerService<H, T, S>

impl<H, T, S> UnwindSafe for HandlerService<H, T, S>

impl<H, T, S, B> Service for HandlerService<H, T, S>

fn poll_ready(self: &mut Self, _cx: &mut Context<'_>) -> Poll<Result<(), <Self as >::Error>>
fn call(self: &mut Self, req: Request<B>) -> <Self as >::Future

impl<H, T, S, L> Service for HandlerService<H, T, S>

fn poll_ready(self: &mut Self, _cx: &mut Context<'_>) -> Poll<Result<(), <Self as >::Error>>
fn call(self: &mut Self, _req: IncomingStream<'_, L>) -> <Self as >::Future

impl<M, S, Target, Request> MakeService for HandlerService<H, T, S>

fn poll_ready(self: &mut Self, cx: &mut Context<'_>) -> Poll<Result<(), <M as MakeService<Target, Request>>::MakeError>>
fn make_service(self: &mut Self, target: Target) -> <M as MakeService<Target, Request>>::Future

impl<S, R> ServiceExt for HandlerService<H, T, S>

fn into_make_service(self: Self) -> IntoMakeService<S>
fn into_make_service_with_connect_info<C>(self: Self) -> IntoMakeServiceWithConnectInfo<S, C>

impl<T> Any for HandlerService<H, T, S>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for HandlerService<H, T, S>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for HandlerService<H, T, S>

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

impl<T> CloneToUninit for HandlerService<H, T, S>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for HandlerService<H, T, S>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> FromRef for HandlerService<H, T, S>

fn from_ref(input: &T) -> T

impl<T> Instrument for HandlerService<H, T, S>

impl<T> Same for HandlerService<H, T, S>

impl<T> ToOwned for HandlerService<H, T, S>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> WithSubscriber for HandlerService<H, T, S>

impl<T, Request> ServiceExt for HandlerService<H, T, S>

impl<T, U> Into for HandlerService<H, T, S>

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for HandlerService<H, T, S>

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

impl<T, U> TryInto for HandlerService<H, T, S>

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

impl<V, T> VZip for HandlerService<H, T, S>

fn vzip(self: Self) -> V