From 3026e341f871ffdaa7b6a69703ca63eef2b67fd7 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Mon, 3 Apr 2023 03:05:27 +0000 Subject: refactor(returnable): seperate contexts --- src/context.rs | 25 +++++++++++++++ src/lib.rs | 2 +- src/module.rs | 2 +- src/response/macros.rs | 12 +++---- src/returnable.rs | 85 -------------------------------------------------- src/router.rs | 4 +-- 6 files changed, 35 insertions(+), 95 deletions(-) create mode 100644 src/context.rs delete mode 100644 src/returnable.rs (limited to 'src') 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 . +// Copyright (C) 2022-2022 Fuwn +// +// 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 . +// +// Copyright (C) 2022-2022 Fuwn +// 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 // 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 . -// Copyright (C) 2022-2022 Fuwn -// -// 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 . -// -// Copyright (C) 2022-2022 Fuwn -// 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, -} -impl<'a> RouteContext<'a> { - pub const fn new( - tcp: &'a TcpStream, - url: &'a Url, - params: &'a Params<'a, 'a>, - certificate: &'a Option, - ) -> Self { - Self { - tcp, - url, - params, - certificate, - } - } -} - -pub struct ErrorContext<'a> { - pub tcp: &'a TcpStream, - pub url: &'a Url, - pub certificate: &'a Option, -} -impl<'a> ErrorContext<'a> { - pub const fn new( - tcp: &'a TcpStream, - url: &'a Url, - certificate: &'a Option, - ) -> 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, -} -impl<'a> CallbackContext<'a> { - pub const fn new( - tcp: &'a TcpStream, - url: &'a Url, - params: Option<&'a Params<'a, 'a>>, - certificate: &'a Option, - ) -> 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 { -- cgit v1.2.3