pub struct Router<T: Clone>(/* private fields */);Expand description
Router
Implementations§
Source§impl<T: Clone> Router<T>
impl<T: Clone> Router<T>
Sourcepub fn handle(&self, req: &Request) -> Response
pub fn handle(&self, req: &Request) -> Response
Handle request
Examples found in repository?
More examples
examples/small-router-context.rs (line 45)
33fn main() {
34 let ctx = Context {
35 data: "Data".to_string(),
36 };
37 let router = RouterBuilder::with(ctx)
38 .get("/", home)
39 .get("/about", about)
40 .fallback(not_found)
41 .build();
42
43 let listener = TcpListener::bind((Ipv4Addr::LOCALHOST, 8080))
44 .unwrap_or_else(|_| panic!("Can't bind to port"));
45 small_http::serve(listener, move |req| router.handle(req));
46}examples/small-router-layers.rs (line 65)
51fn main() {
52 let ctx = Context {
53 data: "Data".to_string(),
54 };
55 let router = RouterBuilder::with(ctx)
56 .pre_layer(cors_pre_layer)
57 .post_layer(cors_post_layer)
58 .get("/", home)
59 .get("/about", about)
60 .fallback(not_found)
61 .build();
62
63 let listener = TcpListener::bind((Ipv4Addr::LOCALHOST, 8080))
64 .unwrap_or_else(|_| panic!("Can't bind to port"));
65 small_http::serve(listener, move |req| router.handle(req));
66}Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Router<T>
impl<T> RefUnwindSafe for Router<T>where
T: RefUnwindSafe,
impl<T> Send for Router<T>
impl<T> Sync for Router<T>
impl<T> Unpin for Router<T>
impl<T> UnwindSafe for Router<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more