Skip to main content

boxed

Function boxed 

Source
pub fn boxed<H: Handler>(h: H) -> BoxHandler
Expand description

Box a Handler into a shareable BoxHandler for storage in the Router.

This accepts any H: Handler. Extractor closures are not Handlers directly — convert them first with IntoHandler::into_handler (the router builders do this for you). A BoxHandler is itself a Handler, so it may be re-boxed.

use churust_core::{boxed, Call, IntoHandler};
use http::{HeaderMap, Method};
use bytes::Bytes;
let handler = boxed((|_c: Call| async { "hi" }).into_handler());
let call = Call::new(Method::GET, "/".parse().unwrap(), HeaderMap::new(), Bytes::new());
let res = handler.handle(call).await;
assert_eq!(res.body.as_slice(), Some(&b"hi"[..]));