aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/tutorial01/main.rs8
-rw-r--r--examples/tutorial01/polls/urls.rs2
-rw-r--r--examples/tutorial01/polls/views.rs2
-rw-r--r--src/contrib/admin/mod.rs1
-rw-r--r--src/contrib/admin/site/mod.rs1
-rw-r--r--src/contrib/admin/site/urls.rs3
-rw-r--r--src/contrib/mod.rs1
-rw-r--r--src/http/mod.rs3
-rw-r--r--src/lib.rs12
-rw-r--r--src/urls/mod.rs16
10 files changed, 37 insertions, 12 deletions
diff --git a/examples/tutorial01/main.rs b/examples/tutorial01/main.rs
index f460e96..3e8f999 100644
--- a/examples/tutorial01/main.rs
+++ b/examples/tutorial01/main.rs
@@ -3,11 +3,11 @@ use tosin::urls::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 const URL_PATTERNS: &[Path] = &[
+ Path::Include { url: "polls/", content: polls::urls::URL_PATTERNS },
+ Path::Include { url: "admin/", content: admin::site::urls::URL_PATTERNS },
];
fn main() {
- tosin::run_server(url_patterns);
+ tosin::run_server(URL_PATTERNS);
}
diff --git a/examples/tutorial01/polls/urls.rs b/examples/tutorial01/polls/urls.rs
index e978920..d56b8c9 100644
--- a/examples/tutorial01/polls/urls.rs
+++ b/examples/tutorial01/polls/urls.rs
@@ -2,6 +2,6 @@ use tosin::urls::Path;
use super::views;
-pub const url_patterns: &[Path] = [
+pub const URL_PATTERNS: &[Path] = &[
Path::View { url: "", view: views::index, name: "index" },
];
diff --git a/examples/tutorial01/polls/views.rs b/examples/tutorial01/polls/views.rs
index 8678e97..23b740d 100644
--- a/examples/tutorial01/polls/views.rs
+++ b/examples/tutorial01/polls/views.rs
@@ -1,5 +1,5 @@
use tosin::http::{Request, Response};
-pub async fn index(request: Request) -> Response {
+pub fn index(request: Request) -> Response {
Response("Hello, world. You're at the polls index.")
}
diff --git a/src/contrib/admin/mod.rs b/src/contrib/admin/mod.rs
new file mode 100644
index 0000000..4d481aa
--- /dev/null
+++ b/src/contrib/admin/mod.rs
@@ -0,0 +1 @@
+pub mod site;
diff --git a/src/contrib/admin/site/mod.rs b/src/contrib/admin/site/mod.rs
new file mode 100644
index 0000000..c8faf42
--- /dev/null
+++ b/src/contrib/admin/site/mod.rs
@@ -0,0 +1 @@
+pub mod urls;
diff --git a/src/contrib/admin/site/urls.rs b/src/contrib/admin/site/urls.rs
new file mode 100644
index 0000000..5e81c4e
--- /dev/null
+++ b/src/contrib/admin/site/urls.rs
@@ -0,0 +1,3 @@
+use crate::urls::Path;
+
+pub const URL_PATTERNS: &[Path] = &[];
diff --git a/src/contrib/mod.rs b/src/contrib/mod.rs
new file mode 100644
index 0000000..92918b0
--- /dev/null
+++ b/src/contrib/mod.rs
@@ -0,0 +1 @@
+pub mod admin;
diff --git a/src/http/mod.rs b/src/http/mod.rs
new file mode 100644
index 0000000..69a0706
--- /dev/null
+++ b/src/http/mod.rs
@@ -0,0 +1,3 @@
+pub struct Request {}
+
+pub struct Response(pub &'static str);
diff --git a/src/lib.rs b/src/lib.rs
index 31e1bb2..28e6ab9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,7 +1,7 @@
-#[cfg(test)]
-mod tests {
- #[test]
- fn it_works() {
- assert_eq!(2 + 2, 4);
- }
+pub mod contrib;
+pub mod http;
+pub mod urls;
+
+pub fn run_server(url_patterns: &[urls::Path]) {
+ todo!();
}
diff --git a/src/urls/mod.rs b/src/urls/mod.rs
new file mode 100644
index 0000000..1acf186
--- /dev/null
+++ b/src/urls/mod.rs
@@ -0,0 +1,16 @@
+use crate::http::{Request, Response};
+
+pub type View = fn(Request) -> Response;
+
+pub enum Path {
+ View {
+ url: &'static str,
+ view: View,
+ name: &'static str,
+ },
+
+ Include {
+ url: &'static str,
+ content: &'static [Path],
+ },
+}