aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-05-05 01:33:55 +0000
committerFuwn <[email protected]>2023-05-05 01:33:55 +0000
commitd66da17c17239408f2ddbc2794621e2d947056a3 (patch)
treee448da50c46c429f6ca672aa070577766fffc9bc /src
parentdocs(rossweisse): revert to implementation (diff)
downloadwindmark-d66da17c17239408f2ddbc2794621e2d947056a3.tar.xz
windmark-d66da17c17239408f2ddbc2794621e2d947056a3.zip
feat(windmark): prelude feature flag
Diffstat (limited to 'src')
-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
8 files changed, 46 insertions, 18 deletions
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",
+ )
}
}};
}