diff options
| author | Fuwn <[email protected]> | 2023-04-03 03:06:26 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-04-03 03:06:26 +0000 |
| commit | 3c030a23833a650af890491ef6e969f93c94b466 (patch) | |
| tree | 3daa321ea0eafa5df57172d587b0d67d4a70f56a | |
| parent | refactor(returnable): seperate contexts (diff) | |
| download | windmark-3c030a23833a650af890491ef6e969f93c94b466.tar.xz windmark-3c030a23833a650af890491ef6e969f93c94b466.zip | |
refactor(context): callback -> hook
| -rw-r--r-- | examples/windmark.rs | 6 | ||||
| -rw-r--r-- | src/context.rs | 4 | ||||
| -rw-r--r-- | src/module.rs | 6 | ||||
| -rw-r--r-- | src/router.rs | 16 |
4 files changed, 16 insertions, 16 deletions
diff --git a/examples/windmark.rs b/examples/windmark.rs index ed02192..c660f3f 100644 --- a/examples/windmark.rs +++ b/examples/windmark.rs @@ -23,7 +23,7 @@ extern crate log; use windmark::{ response::Response, - context::{CallbackContext, RouteContext}, + context::{HookContext, RouteContext}, success, Router, }; @@ -37,7 +37,7 @@ impl windmark::Module for Clicker { println!("clicker has been attached!"); } - fn on_pre_route(&mut self, context: CallbackContext<'_>) { + fn on_pre_route(&mut self, context: HookContext<'_>) { self.clicks += 1; info!( @@ -47,7 +47,7 @@ impl windmark::Module for Clicker { ); } - 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(), 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(), |