Add example and change some code
This commit is contained in:
parent
036c6f873e
commit
91cc658d86
5 changed files with 411 additions and 5 deletions
|
@ -1,7 +1,5 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use tiny_http::Request;
|
||||
use crate::router::Router;
|
||||
|
||||
pub trait Controller {
|
||||
fn register_routes(&self) -> HashMap<String, fn(Request)>;
|
||||
fn register_routes(&self, router: &mut impl Router);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,11 @@ use crate::controller::Controller;
|
|||
pub trait Router {
|
||||
fn new() -> Self;
|
||||
fn route(&self, request: Request);
|
||||
fn add_controller(&mut self, controller: impl Controller);
|
||||
fn add_controller(&mut self, controller: impl Controller)
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
controller.register_routes(self);
|
||||
}
|
||||
fn add_route(&mut self, route: &str, route_function: fn(Request));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue