aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-04-03 03:06:26 +0000
committerFuwn <[email protected]>2023-04-03 03:06:26 +0000
commit3c030a23833a650af890491ef6e969f93c94b466 (patch)
tree3daa321ea0eafa5df57172d587b0d67d4a70f56a /src
parentrefactor(returnable): seperate contexts (diff)
downloadwindmark-3c030a23833a650af890491ef6e969f93c94b466.tar.xz
windmark-3c030a23833a650af890491ef6e969f93c94b466.zip
refactor(context): callback -> hook
Diffstat (limited to 'src')
-rw-r--r--src/context.rs4
-rw-r--r--src/module.rs6
-rw-r--r--src/router.rs16
3 files changed, 13 insertions, 13 deletions
diff --git a/src/context.rs b/src/context.rs
index 21fdcc8..03c0912 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -16,10 +16,10 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-mod callback;
+mod hook;
mod error;
mod route;
-pub use callback::CallbackContext;
+pub use hook::HookContext;
pub use error::ErrorContext;
pub use route::RouteContext;
diff --git a/src/module.rs b/src/module.rs
index 9365777..0c2a67b 100644
--- a/src/module.rs
+++ b/src/module.rs
@@ -16,15 +16,15 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use crate::{context::CallbackContext, Router};
+use crate::{context::HookContext, Router};
pub trait Module {
/// Called right after the module is attached.
fn on_attach(&mut self, _: &mut Router) {}
/// Called before a route is mounted.
- fn on_pre_route(&mut self, _: CallbackContext<'_>) {}
+ fn on_pre_route(&mut self, _: HookContext<'_>) {}
/// Called after a route is mounted.
- fn on_post_route(&mut self, _: CallbackContext<'_>) {}
+ fn on_post_route(&mut self, _: HookContext<'_>) {}
}
diff --git a/src/router.rs b/src/router.rs
index 0862513..4e9c0a2 100644
--- a/src/router.rs
+++ b/src/router.rs
@@ -38,7 +38,7 @@ use crate::{
},
module::Module,
response::Response,
- context::{CallbackContext, ErrorContext, RouteContext},
+ context::{HookContext, ErrorContext, RouteContext},
};
macro_rules! or_error {
@@ -316,7 +316,7 @@ impl Router {
let route = &mut self.routes.at(&fixed_path);
for module in &mut *self.modules.lock().unwrap() {
- module.on_pre_route(CallbackContext::new(
+ module.on_pre_route(HookContext::new(
stream.get_ref(),
&url,
route.as_ref().map_or(None, |route| Some(&route.params)),
@@ -324,7 +324,7 @@ impl Router {
));
}
- (*self.pre_route_callback).lock().unwrap()(CallbackContext::new(
+ (*self.pre_route_callback).lock().unwrap()(HookContext::new(
stream.get_ref(),
&url,
route.as_ref().map_or(None, |route| Some(&route.params)),
@@ -381,7 +381,7 @@ impl Router {
};
for module in &mut *self.modules.lock().unwrap() {
- module.on_post_route(CallbackContext::new(
+ module.on_post_route(HookContext::new(
stream.get_ref(),
&url,
route.as_ref().map_or(None, |route| Some(&route.params)),
@@ -390,7 +390,7 @@ impl Router {
}
(*self.post_route_callback).lock().unwrap()(
- CallbackContext::new(
+ HookContext::new(
stream.get_ref(),
&url,
route.as_ref().map_or(None, |route| Some(&route.params)),
@@ -653,7 +653,7 @@ impl Router {
///
/// ```rust
/// use log::info;
- /// use windmark::{context::CallbackContext, Response, Router};
+ /// use windmark::{context::HookContext, Response, Router};
///
/// #[derive(Default)]
/// struct Clicker {
@@ -664,7 +664,7 @@ impl Router {
/// info!("clicker has been attached!");
/// }
///
- /// fn on_pre_route(&mut self, context: CallbackContext<'_>) {
+ /// fn on_pre_route(&mut self, context: HookContext<'_>) {
/// self.clicks += 1;
///
/// info!(
@@ -674,7 +674,7 @@ impl Router {
/// );
/// }
///
- /// fn on_post_route(&mut self, context: CallbackContext<'_>) {
+ /// fn on_post_route(&mut self, context: HookContext<'_>) {
/// info!(
/// "clicker has been called post-route on {} with {} clicks!",
/// context.url.path(),