Struct routerify::RouterService [−][src]
A Service
to process incoming requests.
This RouterService<B, E>
type accepts two type parameters: B
and E
.
- The
B
represents the response body type which will be used by route handlers and the middlewares and this body type must implement the HttpBody trait. For an instance,B
could be hyper::Body type. - The
E
represents any error type which will be used by route handlers and the middlewares. This error type must implement the std::error::Error.
Examples
use hyper::{Body, Request, Response, Server}; use routerify::{Router, RouterService}; use std::convert::Infallible; use std::net::SocketAddr; // A handler for "/" page. async fn home(_: Request<Body>) -> Result<Response<Body>, Infallible> { Ok(Response::new(Body::from("Home page"))) } fn router() -> Router<Body, Infallible> { Router::builder() .get("/", home) .build() .unwrap() } #[tokio::main] async fn main() { let router = router(); // Create a Service from the router above to handle incoming requests. let service = RouterService::new(router).unwrap(); let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); // Create a server by passing the created service to `.serve` method. let server = Server::bind(&addr).serve(service); println!("App is running on: {}", addr); if let Err(err) = server.await { eprintln!("Server error: {}", err); } }
Implementations
impl<B: HttpBody + Send + Sync + 'static, E: Into<Box<dyn Error + Send + Sync>> + 'static> RouterService<B, E>
[src]
pub fn new(router: Router<B, E>) -> Result<RouterService<B, E>>
[src]
Creates a new service with the provided router and it’s ready to be used with the hyper serve
method.
Trait Implementations
impl<B: Debug, E: Debug> Debug for RouterService<B, E>
[src]
impl<B: HttpBody + Send + Sync + 'static, E: Into<Box<dyn Error + Send + Sync>> + 'static> Service<&'_ AddrStream> for RouterService<B, E>
[src]
type Response = RequestService<B, E>
Responses given by the service.
type Error = Infallible
Errors produced by the service.
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>
The future response value.
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
[src]
fn call(&mut self, conn: &AddrStream) -> Self::Future
[src]
Auto Trait Implementations
impl<B, E> !RefUnwindSafe for RouterService<B, E>
impl<B, E> Send for RouterService<B, E>
impl<B, E> Sync for RouterService<B, E>
impl<B, E> Unpin for RouterService<B, E>
impl<B, E> !UnwindSafe for RouterService<B, E>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,