nutt_web/modules/router/
mod.rs1use crate::http::method::Method;
2use crate::modules::router::route::Route;
3use std::collections::HashMap;
4pub mod route;
5
6pub struct Router {
7 routes: HashMap<(Method, String), Route>,
8}
9
10impl Default for Router {
11 fn default() -> Self {
12 Self::new()
13 }
14}
15
16impl Router {
17 pub fn new() -> Self {
18 Self {
19 routes: HashMap::new(),
20 }
21 }
22
23 pub fn insert(&mut self, key: (Method, String), route: Route) {
24 self.routes.insert(key, route);
25 }
26
27 pub fn get(&self, key: (Method, String)) -> Option<&Route> {
28 self.routes.get(&key)
29 }
30}
31
32#[macro_export]
33macro_rules! routes {
34 ($elem:expr; $n:expr) => (
35 vec![($elem)()]
36 );
37 ($($x:expr),+ $(,)?) => (
38 Vec::from(vec![$(($x)()),+])
39 );
40 () => (
41 Vec::new()
42 )
43 }