aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-04-03 03:05:27 +0000
committerFuwn <[email protected]>2023-04-03 03:05:27 +0000
commit3026e341f871ffdaa7b6a69703ca63eef2b67fd7 (patch)
treeecdaf57aa6e39cdfc56659813d6b65335f6f512e
parentrefactor(handler): move traits (diff)
downloadwindmark-3026e341f871ffdaa7b6a69703ca63eef2b67fd7.tar.xz
windmark-3026e341f871ffdaa7b6a69703ca63eef2b67fd7.zip
refactor(returnable): seperate contexts
-rw-r--r--examples/windmark.rs2
-rw-r--r--src/context.rs25
-rw-r--r--src/lib.rs2
-rw-r--r--src/module.rs2
-rw-r--r--src/response/macros.rs12
-rw-r--r--src/returnable.rs85
-rw-r--r--src/router.rs4
7 files changed, 36 insertions, 96 deletions
diff --git a/examples/windmark.rs b/examples/windmark.rs
index e10c343..ed02192 100644
--- a/examples/windmark.rs
+++ b/examples/windmark.rs
@@ -23,7 +23,7 @@ extern crate log;
use windmark::{
response::Response,
- returnable::{CallbackContext, RouteContext},
+ context::{CallbackContext, RouteContext},
success,
Router,
};
diff --git a/src/context.rs b/src/context.rs
new file mode 100644
index 0000000..21fdcc8
--- /dev/null
+++ b/src/context.rs
@@ -0,0 +1,25 @@
+// This file is part of Windmark <https://github.com/gemrest/windmark>.
+// Copyright (C) 2022-2022 Fuwn <[email protected]>
+//
+// 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-2022 Fuwn <[email protected]>
+// SPDX-License-Identifier: GPL-3.0-only
+
+mod callback;
+mod error;
+mod route;
+
+pub use callback::CallbackContext;
+pub use error::ErrorContext;
+pub use route::RouteContext;
diff --git a/src/lib.rs b/src/lib.rs
index 642182c..b8b53ed 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -33,7 +33,7 @@
pub mod handler;
pub mod module;
pub mod response;
-pub mod returnable;
+pub mod context;
pub mod router;
pub mod utilities;
diff --git a/src/module.rs b/src/module.rs
index 0d2d2f5..9365777 100644
--- a/src/module.rs
+++ b/src/module.rs
@@ -16,7 +16,7 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use crate::{returnable::CallbackContext, Router};
+use crate::{context::CallbackContext, Router};
pub trait Module {
/// Called right after the module is attached.
diff --git a/src/response/macros.rs b/src/response/macros.rs
index 54e6a8b..339da07 100644
--- a/src/response/macros.rs
+++ b/src/response/macros.rs
@@ -23,10 +23,10 @@ macro_rules! response {
#[macro_export]
macro_rules! $name {
($body:expr /* $(,)? */) => {
- |_: ::windmark::returnable::RouteContext<'_>| ::windmark::Response::$name($body)
+ |_: ::windmark::context::RouteContext<'_>| ::windmark::Response::$name($body)
};
($context:ident, $body:expr /* $(,)? */) => {
- |$context: ::windmark::returnable::RouteContext<'_>| ::windmark::Response::$name($body)
+ |$context: ::windmark::context::RouteContext<'_>| ::windmark::Response::$name($body)
};
}
)*
@@ -57,7 +57,7 @@ response!(certificate_not_valid);
#[macro_export]
macro_rules! binary_success {
($body:expr, $mime:expr) => {
- |_: ::windmark::returnable::RouteContext<'_>| {
+ |_: ::windmark::context::RouteContext<'_>| {
::windmark::Response::binary_success($body, $mime)
}
};
@@ -68,7 +68,7 @@ macro_rules! binary_success {
feature to be enabled"
);
- |_: ::windmark::returnable::RouteContext<'_>| {
+ |_: ::windmark::context::RouteContext<'_>| {
#[cfg(feature = "auto-deduce-mime")]
return ::windmark::Response::binary_success_auto($body);
@@ -78,7 +78,7 @@ macro_rules! binary_success {
}
}};
($context:ident, $body:expr, $mime:expr) => {
- |$context: ::windmark::returnable::RouteContext<'_>| {
+ |$context: ::windmark::context::RouteContext<'_>| {
::windmark::Response::binary_success($body, $mime)
}
};
@@ -89,7 +89,7 @@ macro_rules! binary_success {
feature to be enabled"
);
- |$context: ::windmark::returnable::RouteContext<'_>| {
+ |$context: ::windmark::context::RouteContext<'_>| {
#[cfg(feature = "auto-deduce-mime")]
return ::windmark::Response::binary_success_auto($body);
diff --git a/src/returnable.rs b/src/returnable.rs
deleted file mode 100644
index ef34c77..0000000
--- a/src/returnable.rs
+++ /dev/null
@@ -1,85 +0,0 @@
-// This file is part of Windmark <https://github.com/gemrest/windmark>.
-// Copyright (C) 2022-2022 Fuwn <[email protected]>
-//
-// 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-2022 Fuwn <[email protected]>
-// SPDX-License-Identifier: GPL-3.0-only
-
-use matchit::Params;
-use openssl::x509::X509;
-use tokio::net::TcpStream;
-use url::Url;
-
-pub struct RouteContext<'a> {
- pub tcp: &'a TcpStream,
- pub url: &'a Url,
- pub params: &'a Params<'a, 'a>,
- pub certificate: &'a Option<X509>,
-}
-impl<'a> RouteContext<'a> {
- pub const fn new(
- tcp: &'a TcpStream,
- url: &'a Url,
- params: &'a Params<'a, 'a>,
- certificate: &'a Option<X509>,
- ) -> Self {
- Self {
- tcp,
- url,
- params,
- certificate,
- }
- }
-}
-
-pub struct ErrorContext<'a> {
- pub tcp: &'a TcpStream,
- pub url: &'a Url,
- pub certificate: &'a Option<X509>,
-}
-impl<'a> ErrorContext<'a> {
- pub const fn new(
- tcp: &'a TcpStream,
- url: &'a Url,
- certificate: &'a Option<X509>,
- ) -> Self {
- Self {
- tcp,
- url,
- certificate,
- }
- }
-}
-
-pub struct CallbackContext<'a> {
- pub tcp: &'a TcpStream,
- pub url: &'a Url,
- pub params: Option<&'a Params<'a, 'a>>,
- pub certificate: &'a Option<X509>,
-}
-impl<'a> CallbackContext<'a> {
- pub const fn new(
- tcp: &'a TcpStream,
- url: &'a Url,
- params: Option<&'a Params<'a, 'a>>,
- certificate: &'a Option<X509>,
- ) -> Self {
- Self {
- tcp,
- url,
- params,
- certificate,
- }
- }
-}
diff --git a/src/router.rs b/src/router.rs
index 5c1fcfa..0862513 100644
--- a/src/router.rs
+++ b/src/router.rs
@@ -38,7 +38,7 @@ use crate::{
},
module::Module,
response::Response,
- returnable::{CallbackContext, ErrorContext, RouteContext},
+ context::{CallbackContext, ErrorContext, RouteContext},
};
macro_rules! or_error {
@@ -653,7 +653,7 @@ impl Router {
///
/// ```rust
/// use log::info;
- /// use windmark::{returnable::CallbackContext, Response, Router};
+ /// use windmark::{context::CallbackContext, Response, Router};
///
/// #[derive(Default)]
/// struct Clicker {