Add example and change some code
All checks were successful
Cargo Build & Test / Test publish (pull_request) Successful in 32s
Cargo Build & Test / Tests (pull_request) Successful in 36s
Cargo Build & Test / check-cargo-version (pull_request) Successful in 5s

This commit is contained in:
Jan K9f 2024-08-21 14:55:30 +02:00
commit 91cc658d86
Signed by: jank
GPG key ID: B267751B8AE29EFE
5 changed files with 411 additions and 5 deletions

View file

@ -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);
}

View file

@ -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));
}