From 4c8940569e5729213b7eee6f3d5be39b745b697b Mon Sep 17 00:00:00 2001 From: Melody Horn / boringcactus Date: Sat, 12 Jun 2021 23:24:33 -0600 Subject: actually implement the easy example --- examples/tutorial01/main.rs | 15 +++++++++------ examples/tutorial01/polls/urls.rs | 10 ++++++---- examples/tutorial01/polls/views.rs | 6 +++--- 3 files changed, 18 insertions(+), 13 deletions(-) (limited to 'examples') diff --git a/examples/tutorial01/main.rs b/examples/tutorial01/main.rs index 3e8f999..62c32cd 100644 --- a/examples/tutorial01/main.rs +++ b/examples/tutorial01/main.rs @@ -1,13 +1,16 @@ use tosin::contrib::admin; -use tosin::urls::Path; +use tosin::http::Filter; +use tosin::urls::{UrlMap, path}; mod polls; -pub const URL_PATTERNS: &[Path] = &[ - Path::Include { url: "polls/", content: polls::urls::URL_PATTERNS }, - Path::Include { url: "admin/", content: admin::site::urls::URL_PATTERNS }, -]; +pub fn urls() -> UrlMap { + path!("polls" / ..).and(polls::urls::urls()) + .or(path!("admin" / ..).and(admin::site::urls::urls())) + .unify() + .boxed() +} fn main() { - tosin::run_server(URL_PATTERNS); + tosin::run_server(urls()); } diff --git a/examples/tutorial01/polls/urls.rs b/examples/tutorial01/polls/urls.rs index d56b8c9..184c6f8 100644 --- a/examples/tutorial01/polls/urls.rs +++ b/examples/tutorial01/polls/urls.rs @@ -1,7 +1,9 @@ -use tosin::urls::Path; +use tosin::http::Filter; +use tosin::urls::{UrlMap, path}; use super::views; -pub const URL_PATTERNS: &[Path] = &[ - Path::View { url: "", view: views::index, name: "index" }, -]; +pub fn urls() -> UrlMap { + path::end().map(views::index) // TODO name: "index" + .boxed() +} diff --git a/examples/tutorial01/polls/views.rs b/examples/tutorial01/polls/views.rs index 23b740d..4859cec 100644 --- a/examples/tutorial01/polls/views.rs +++ b/examples/tutorial01/polls/views.rs @@ -1,5 +1,5 @@ -use tosin::http::{Request, Response}; +use tosin::http::{Reply, Response}; -pub fn index(request: Request) -> Response { - Response("Hello, world. You're at the polls index.") +pub fn index() -> Response { + "Hello, world. You're at the polls index.".into_response() } -- cgit v1.2.3