1 use crate::response::Response; 2 use axum_core::response::IntoResponse; 3 use http::{Request, StatusCode}; 4 use std::{ 5 convert::Infallible, 6 future::ready, 7 task::{Context, Poll}, 8 }; 9 use tower_service::Service; 10 11 /// A [`Service`] that responds with `404 Not Found` to all requests. 12 /// 13 /// This is used as the bottom service in a method router. You shouldn't have to 14 /// use it manually. 15 #[derive(Clone, Copy, Debug)] 16 pub(super) struct NotFound; 17 18 impl<B> Service<Request<B>> for NotFound 19 where 20 B: Send + 'static, 21 { 22 type Response = Response; 23 type Error = Infallible; 24 type Future = std::future::Ready<Result<Response, Self::Error>>; 25 26 #[inline] poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>27 fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { 28 Poll::Ready(Ok(())) 29 } 30 call(&mut self, _req: Request<B>) -> Self::Future31 fn call(&mut self, _req: Request<B>) -> Self::Future { 32 ready(Ok(StatusCode::NOT_FOUND.into_response())) 33 } 34 } 35