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-layers.rs (line 57)
46fn main() {
47 let router = RouterBuilder::new()
48 .pre_layer(cors_pre_layer)
49 .post_layer(cors_post_layer)
50 .get("/", home)
51 .get("/about", about)
52 .fallback(not_found)
53 .build();
54
55 let listener = TcpListener::bind((Ipv4Addr::LOCALHOST, 8080))
56 .unwrap_or_else(|_| panic!("Can't bind to port"));
57 small_http::serve(listener, move |req| router.handle(req));
58}
examples/small-router-context.rs (line 56)
44fn main() {
45 let ctx = Context {
46 shared_data: Arc::new(RwLock::new("Hello".to_string())),
47 };
48 let router = RouterBuilder::with(ctx)
49 .get("/", home)
50 .get("/about", about)
51 .fallback(not_found)
52 .build();
53
54 let listener = TcpListener::bind((Ipv4Addr::LOCALHOST, 8080))
55 .unwrap_or_else(|_| panic!("Can't bind to port"));
56 small_http::serve(listener, move |req| router.handle(req));
57}
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