aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml1
-rw-r--r--examples/async.rs4
-rw-r--r--examples/async_stateful_module.rs4
-rw-r--r--examples/binary.rs2
-rw-r--r--examples/callbacks.rs4
-rw-r--r--examples/certificate.rs4
-rw-r--r--examples/default_logger.rs2
-rw-r--r--examples/empty.rs2
-rw-r--r--examples/error_handler.rs4
-rw-r--r--examples/fix_path.rs2
-rw-r--r--examples/input.rs4
-rw-r--r--examples/mime.rs4
-rw-r--r--examples/parameters.rs2
-rw-r--r--examples/partial.rs2
-rw-r--r--examples/query.rs2
-rw-r--r--examples/responses.rs2
-rw-r--r--examples/simple_async_std.rs6
-rw-r--r--examples/simple_tokio.rs6
-rw-r--r--examples/stateful_module.rs4
-rw-r--r--examples/stateless_module.rs6
-rw-r--r--examples/struct_router.rs7
-rw-r--r--rossweisse/src/implementations/router/fields.rs6
-rw-r--r--src/handler/hooks/post_route.rs2
-rw-r--r--src/handler/response/error.rs2
-rw-r--r--src/handler/response/route.rs2
-rw-r--r--src/lib.rs5
-rw-r--r--src/module/asynchronous.rs2
-rw-r--r--src/module/sync.rs2
-rw-r--r--src/prelude.rs23
-rw-r--r--src/response/macros.rs26
30 files changed, 88 insertions, 56 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 5fbfbda..47cf169 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -24,6 +24,7 @@ auto-deduce-mime = ["tree_magic"]
response-macros = []
tokio = ["dep:tokio", "tokio-openssl"]
async-std = ["dep:async-std", "async-std-openssl"]
+prelude = []
[dependencies]
# SSL
diff --git a/examples/async.rs b/examples/async.rs
index d803ad6..f2674f0 100644
--- a/examples/async.rs
+++ b/examples/async.rs
@@ -19,7 +19,7 @@
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
- let mut router = windmark::Router::new();
+ let mut router = windmark::router::Router::new();
#[cfg(feature = "tokio")]
let async_clicks = std::sync::Arc::new(tokio::sync::Mutex::new(0));
#[cfg(feature = "async-std")]
@@ -35,7 +35,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
*clicks += 1;
- windmark::Response::success(*clicks)
+ windmark::response::Response::success(*clicks)
}
});
router.mount(
diff --git a/examples/async_stateful_module.rs b/examples/async_stateful_module.rs
index 3c35486..e19eb69 100644
--- a/examples/async_stateful_module.rs
+++ b/examples/async_stateful_module.rs
@@ -17,7 +17,7 @@
//! `cargo run --example async_stateful_module --features response-macros`
-use windmark::{context::HookContext, Router};
+use windmark::{context::HookContext, router::Router};
#[derive(Default)]
struct Clicker {
@@ -25,7 +25,7 @@ struct Clicker {
}
#[async_trait::async_trait]
-impl windmark::AsyncModule for Clicker {
+impl windmark::module::AsyncModule for Clicker {
async fn on_attach(&mut self, _router: &mut Router) {
println!("module 'clicker' has been attached!");
}
diff --git a/examples/binary.rs b/examples/binary.rs
index 2fbb652..3a86c17 100644
--- a/examples/binary.rs
+++ b/examples/binary.rs
@@ -22,7 +22,7 @@
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
- let mut router = windmark::Router::new();
+ let mut router = windmark::router::Router::new();
router.set_private_key_file("windmark_private.pem");
router.set_certificate_file("windmark_public.pem");
diff --git a/examples/callbacks.rs b/examples/callbacks.rs
index 58826e2..9d4acc1 100644
--- a/examples/callbacks.rs
+++ b/examples/callbacks.rs
@@ -21,7 +21,7 @@ use windmark::context::HookContext;
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
- windmark::Router::new()
+ windmark::router::Router::new()
.set_private_key_file("windmark_private.pem")
.set_certificate_file("windmark_public.pem")
.mount("/", windmark::success!("Hello!"))
@@ -33,7 +33,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
)
})
.set_post_route_callback(
- |context: HookContext, content: &mut windmark::Response| {
+ |context: HookContext, content: &mut windmark::response::Response| {
content.content = content.content.replace("Hello", "Hi");
println!(
diff --git a/examples/certificate.rs b/examples/certificate.rs
index f93d724..6cd6def 100644
--- a/examples/certificate.rs
+++ b/examples/certificate.rs
@@ -17,11 +17,11 @@
//! `cargo run --example certificate --features response-macros`
-use windmark::Response;
+use windmark::response::Response;
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
- windmark::Router::new()
+ windmark::router::Router::new()
.set_private_key_file("windmark_private.pem")
.set_certificate_file("windmark_public.pem")
.mount("/secret", |context: windmark::context::RouteContext| {
diff --git a/examples/default_logger.rs b/examples/default_logger.rs
index 994bb6e..f7d5eb1 100644
--- a/examples/default_logger.rs
+++ b/examples/default_logger.rs
@@ -19,7 +19,7 @@
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
- let mut router = windmark::Router::new();
+ let mut router = windmark::router::Router::new();
router.set_private_key_file("windmark_private.pem");
router.set_certificate_file("windmark_public.pem");
diff --git a/examples/empty.rs b/examples/empty.rs
index 02e6254..893fd2b 100644
--- a/examples/empty.rs
+++ b/examples/empty.rs
@@ -19,7 +19,7 @@
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
- windmark::Router::new()
+ windmark::router::Router::new()
.set_private_key_file("windmark_private.pem")
.set_certificate_file("windmark_public.pem")
.run()
diff --git a/examples/error_handler.rs b/examples/error_handler.rs
index 86ec337..93aa9c7 100644
--- a/examples/error_handler.rs
+++ b/examples/error_handler.rs
@@ -17,13 +17,13 @@
//! `cargo run --example error_handler`
-use windmark::Response;
+use windmark::response::Response;
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut error_count = 0;
- windmark::Router::new()
+ windmark::router::Router::new()
.set_private_key_file("windmark_private.pem")
.set_certificate_file("windmark_public.pem")
.set_error_handler(move |_| {
diff --git a/examples/fix_path.rs b/examples/fix_path.rs
index 1b64602..fe8fb2c 100644
--- a/examples/fix_path.rs
+++ b/examples/fix_path.rs
@@ -19,7 +19,7 @@
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
- windmark::Router::new()
+ windmark::router::Router::new()
.set_private_key_file("windmark_private.pem")
.set_certificate_file("windmark_public.pem")
.set_fix_path(true)
diff --git a/examples/input.rs b/examples/input.rs
index 75e97cb..e8f3111 100644
--- a/examples/input.rs
+++ b/examples/input.rs
@@ -17,11 +17,11 @@
//! `cargo run --example input`
-use windmark::{context::RouteContext, Response};
+use windmark::{context::RouteContext, response::Response};
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
- windmark::Router::new()
+ windmark::router::Router::new()
.set_private_key_file("windmark_private.pem")
.set_certificate_file("windmark_public.pem")
.mount("/input", |context: RouteContext| {
diff --git a/examples/mime.rs b/examples/mime.rs
index 9f592f5..93ebabb 100644
--- a/examples/mime.rs
+++ b/examples/mime.rs
@@ -19,11 +19,11 @@
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
- windmark::Router::new()
+ windmark::router::Router::new()
.set_private_key_file("windmark_private.pem")
.set_certificate_file("windmark_public.pem")
.mount("/mime", |_| {
- windmark::Response::success("Hello!".to_string())
+ windmark::response::Response::success("Hello!".to_string())
.with_mime("text/plain")
.clone()
})
diff --git a/examples/parameters.rs b/examples/parameters.rs
index e329e09..82a61a5 100644
--- a/examples/parameters.rs
+++ b/examples/parameters.rs
@@ -21,7 +21,7 @@ use windmark::success;
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
- windmark::Router::new()
+ windmark::router::Router::new()
.set_private_key_file("windmark_private.pem")
.set_certificate_file("windmark_public.pem")
.mount(
diff --git a/examples/partial.rs b/examples/partial.rs
index 70e05ab..d49256a 100644
--- a/examples/partial.rs
+++ b/examples/partial.rs
@@ -19,7 +19,7 @@
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
- windmark::Router::new()
+ windmark::router::Router::new()
.set_private_key_file("windmark_private.pem")
.set_certificate_file("windmark_public.pem")
.add_header(|_| "This is fancy art.\n".to_string())
diff --git a/examples/query.rs b/examples/query.rs
index 38fc295..f144795 100644
--- a/examples/query.rs
+++ b/examples/query.rs
@@ -19,7 +19,7 @@
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
- windmark::Router::new()
+ windmark::router::Router::new()
.set_private_key_file("windmark_private.pem")
.set_certificate_file("windmark_public.pem")
.mount(
diff --git a/examples/responses.rs b/examples/responses.rs
index c1bd533..3cb996a 100644
--- a/examples/responses.rs
+++ b/examples/responses.rs
@@ -21,7 +21,7 @@ use windmark::success;
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
- windmark::Router::new()
+ windmark::router::Router::new()
.set_private_key_file("windmark_private.pem")
.set_certificate_file("windmark_public.pem")
.mount(
diff --git a/examples/simple_async_std.rs b/examples/simple_async_std.rs
index 9896590..75cd66e 100644
--- a/examples/simple_async_std.rs
+++ b/examples/simple_async_std.rs
@@ -19,10 +19,12 @@
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
- windmark::Router::new()
+ windmark::router::Router::new()
.set_private_key_file("windmark_private.pem")
.set_certificate_file("windmark_public.pem")
- .mount("/", |_| windmark::Response::success("Hello, async-std!"))
+ .mount("/", |_| {
+ windmark::response::Response::success("Hello, async-std!")
+ })
.run()
.await
}
diff --git a/examples/simple_tokio.rs b/examples/simple_tokio.rs
index 1c9acec..ec64c49 100644
--- a/examples/simple_tokio.rs
+++ b/examples/simple_tokio.rs
@@ -19,10 +19,12 @@
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
- windmark::Router::new()
+ windmark::router::Router::new()
.set_private_key_file("windmark_private.pem")
.set_certificate_file("windmark_public.pem")
- .mount("/", |_| windmark::Response::success("Hello, Tokio!"))
+ .mount("/", |_| {
+ windmark::response::Response::success("Hello, Tokio!")
+ })
.run()
.await
}
diff --git a/examples/stateful_module.rs b/examples/stateful_module.rs
index 4347716..73b7663 100644
--- a/examples/stateful_module.rs
+++ b/examples/stateful_module.rs
@@ -17,14 +17,14 @@
//! `cargo run --example stateful_module --features response-macros`
-use windmark::{context::HookContext, Router};
+use windmark::{context::HookContext, router::Router};
#[derive(Default)]
struct Clicker {
clicks: usize,
}
-impl windmark::Module for Clicker {
+impl windmark::module::Module for Clicker {
fn on_attach(&mut self, _router: &mut Router) {
println!("module 'clicker' has been attached!");
}
diff --git a/examples/stateless_module.rs b/examples/stateless_module.rs
index f43ce16..f747aac 100644
--- a/examples/stateless_module.rs
+++ b/examples/stateless_module.rs
@@ -17,10 +17,10 @@
//! `cargo run --example stateless_module`
-use windmark::Router;
+use windmark::{response::Response, router::Router};
-fn smiley(_context: windmark::context::RouteContext) -> windmark::Response {
- windmark::Response::success("😀")
+fn smiley(_context: windmark::context::RouteContext) -> Response {
+ Response::success("😀")
}
fn emojis(router: &mut Router) { router.mount("/smiley", smiley); }
diff --git a/examples/struct_router.rs b/examples/struct_router.rs
index a636f7d..3401379 100644
--- a/examples/struct_router.rs
+++ b/examples/struct_router.rs
@@ -18,6 +18,7 @@
//! `cargo run --example struct_router`
use rossweisse::route;
+use windmark::response::Response;
#[rossweisse::router]
struct Router {
@@ -27,10 +28,8 @@ struct Router {
#[rossweisse::router]
impl Router {
#[route(index)]
- pub fn index(
- _context: windmark::context::RouteContext,
- ) -> windmark::Response {
- windmark::Response::success("Hello, World!")
+ pub fn index(_context: windmark::context::RouteContext) -> Response {
+ Response::success("Hello, World!")
}
}
diff --git a/rossweisse/src/implementations/router/fields.rs b/rossweisse/src/implementations/router/fields.rs
index a2d0bdf..6c3941a 100644
--- a/rossweisse/src/implementations/router/fields.rs
+++ b/rossweisse/src/implementations/router/fields.rs
@@ -58,7 +58,7 @@ pub fn fields(arguments: TokenStream, item: syn::ItemStruct) -> TokenStream {
fn _new() -> Self {
Self {
#(#new_method_fields)*
- router: ::windmark::Router::new(),
+ router: ::windmark::router::Router::new(),
}
}
@@ -66,7 +66,7 @@ pub fn fields(arguments: TokenStream, item: syn::ItemStruct) -> TokenStream {
self.router.run().await
}
- pub fn router(&mut self) -> &mut ::windmark::Router {
+ pub fn router(&mut self) -> &mut ::windmark::router::Router {
&mut self.router
}
};
@@ -74,7 +74,7 @@ pub fn fields(arguments: TokenStream, item: syn::ItemStruct) -> TokenStream {
let output = quote! {
struct #router_identifier {
#output_fields
- router: ::windmark::Router,
+ router: ::windmark::router::Router,
}
impl #router_identifier {
diff --git a/src/handler/hooks/post_route.rs b/src/handler/hooks/post_route.rs
index 8a92fc6..b8acd35 100644
--- a/src/handler/hooks/post_route.rs
+++ b/src/handler/hooks/post_route.rs
@@ -15,7 +15,7 @@
// Copyright (C) 2022-2023 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use crate::{context::HookContext, Response};
+use crate::{context::HookContext, response::Response};
#[allow(clippy::module_name_repetitions)]
pub trait PostRouteHook: Send + Sync {
diff --git a/src/handler/response/error.rs b/src/handler/response/error.rs
index af73001..a8c2745 100644
--- a/src/handler/response/error.rs
+++ b/src/handler/response/error.rs
@@ -17,7 +17,7 @@
use async_trait::async_trait;
-use crate::{context::ErrorContext, Response};
+use crate::{context::ErrorContext, response::Response};
#[allow(clippy::module_name_repetitions)]
#[async_trait]
diff --git a/src/handler/response/route.rs b/src/handler/response/route.rs
index 2604947..0c0d0e9 100644
--- a/src/handler/response/route.rs
+++ b/src/handler/response/route.rs
@@ -17,7 +17,7 @@
use async_trait::async_trait;
-use crate::{context::RouteContext, Response};
+use crate::{context::RouteContext, response::Response};
#[allow(clippy::module_name_repetitions)]
#[async_trait]
diff --git a/src/lib.rs b/src/lib.rs
index 567655b..968c9a9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -32,6 +32,8 @@
pub mod context;
pub mod handler;
pub mod module;
+#[cfg(feature = "prelude")]
+pub mod prelude;
pub mod response;
pub mod router;
pub mod utilities;
@@ -41,8 +43,5 @@ extern crate log;
#[cfg(feature = "async-std")]
pub use async_std::main;
-pub use module::{AsyncModule, Module};
-pub use response::Response;
-pub use router::Router;
#[cfg(feature = "tokio")]
pub use tokio::main;
diff --git a/src/module/asynchronous.rs b/src/module/asynchronous.rs
index 2459518..219f6c2 100644
--- a/src/module/asynchronous.rs
+++ b/src/module/asynchronous.rs
@@ -20,7 +20,7 @@ use crate::context::HookContext;
#[async_trait::async_trait]
pub trait AsyncModule: Send + Sync {
/// Called right after the module is attached.
- async fn on_attach(&mut self, _: &mut crate::Router) {}
+ async fn on_attach(&mut self, _: &mut crate::router::Router) {}
/// Called before a route is mounted.
async fn on_pre_route(&mut self, _: HookContext) {}
diff --git a/src/module/sync.rs b/src/module/sync.rs
index 4b6de4d..1e1c565 100644
--- a/src/module/sync.rs
+++ b/src/module/sync.rs
@@ -19,7 +19,7 @@ use crate::context::HookContext;
pub trait Module {
/// Called right after the module is attached.
- fn on_attach(&mut self, _: &mut crate::Router) {}
+ fn on_attach(&mut self, _: &mut crate::router::Router) {}
/// Called before a route is mounted.
fn on_pre_route(&mut self, _: HookContext) {}
diff --git a/src/prelude.rs b/src/prelude.rs
new file mode 100644
index 0000000..8a08b48
--- /dev/null
+++ b/src/prelude.rs
@@ -0,0 +1,23 @@
+// This file is part of Windmark <https://github.com/gemrest/windmark>.
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 3.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+// Copyright (C) 2022-2023 Fuwn <[email protected]>
+// SPDX-License-Identifier: GPL-3.0-only
+
+pub use crate::{
+ context,
+ module::{AsyncModule, Module},
+ response::Response,
+ router::Router,
+};
diff --git a/src/response/macros.rs b/src/response/macros.rs
index 9f78c41..976973b 100644
--- a/src/response/macros.rs
+++ b/src/response/macros.rs
@@ -22,10 +22,10 @@ macro_rules! sync_response {
#[macro_export]
macro_rules! $name {
($body:expr /* $(,)? */) => {
- |_: $crate::context::RouteContext| $crate::Response::$name($body)
+ |_: $crate::context::RouteContext| $crate::response::Response::$name($body)
};
($context:ident, $body:expr /* $(,)? */) => {
- |$context: $crate::context::RouteContext| $crate::Response::$name($body)
+ |$context: $crate::context::RouteContext| $crate::response::Response::$name($body)
};
}
)*
@@ -39,10 +39,10 @@ macro_rules! async_response {
#[macro_export]
macro_rules! [< $name _async >] {
($body:expr /* $(,)? */) => {
- |_: $crate::context::RouteContext| async { $crate::Response::$name($body) }
+ |_: $crate::context::RouteContext| async { $crate::response::Response::$name($body) }
};
($context:ident, $body:expr /* $(,)? */) => {
- |$context: $crate::context::RouteContext| async { $crate::Response::$name($body) }
+ |$context: $crate::context::RouteContext| async { $crate::response::Response::$name($body) }
};
}
})*
@@ -86,7 +86,7 @@ response!(binary_success_auto);
macro_rules! binary_success {
($body:expr, $mime:expr) => {
|_: $crate::context::RouteContext| {
- $crate::Response::binary_success($body, $mime)
+ $crate::response::Response::binary_success($body, $mime)
}
};
($body:expr) => {{
@@ -98,16 +98,19 @@ macro_rules! binary_success {
|_: $crate::context::RouteContext| {
#[cfg(feature = "auto-deduce-mime")]
- return $crate::Response::binary_success_auto($body);
+ return $crate::response::Response::binary_success_auto($body);
// Suppress item not found warning
#[cfg(not(feature = "auto-deduce-mime"))]
- $crate::Response::binary_success($body, "application/octet-stream")
+ $crate::response::Response::binary_success(
+ $body,
+ "application/octet-stream",
+ )
}
}};
($context:ident, $body:expr, $mime:expr) => {
|$context: $crate::context::RouteContext| {
- $crate::Response::binary_success($body, $mime)
+ $crate::response::Response::binary_success($body, $mime)
}
};
($context:ident, $body:expr) => {{
@@ -119,11 +122,14 @@ macro_rules! binary_success {
|$context: $crate::context::RouteContext| {
#[cfg(feature = "auto-deduce-mime")]
- return $crate::Response::binary_success_auto($body);
+ return $crate::response::Response::binary_success_auto($body);
// Suppress item not found warning
#[cfg(not(feature = "auto-deduce-mime"))]
- $crate::Response::binary_success($body, "application/octet-stream")
+ $crate::response::Response::binary_success(
+ $body,
+ "application/octet-stream",
+ )
}
}};
}