···11+// This file is part of Windmark <https://github.com/gemrest/windmark>.
22+// Copyright (C) 2022-2022 Fuwn <contact@fuwn.me>
33+//
44+// This program is free software: you can redistribute it and/or modify
55+// it under the terms of the GNU General Public License as published by
66+// the Free Software Foundation, version 3.
77+//
88+// This program is distributed in the hope that it will be useful, but
99+// WITHOUT ANY WARRANTY; without even the implied warranty of
1010+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1111+// General Public License for more details.
1212+//
1313+// You should have received a copy of the GNU General Public License
1414+// along with this program. If not, see <http://www.gnu.org/licenses/>.
1515+//
1616+// Copyright (C) 2022-2022 Fuwn <contact@fuwn.me>
1717+// SPDX-License-Identifier: GPL-3.0-only
1818+1919+use crate::{context::HookContext, Router};
2020+2121+#[async_trait::async_trait]
2222+pub trait AsyncModule: Send + Sync {
2323+ /// Called right after the module is attached.
2424+ async fn on_attach(&mut self, _: &mut Router) {}
2525+2626+ /// Called before a route is mounted.
2727+ async fn on_pre_route(&mut self, _: HookContext<'_>) {}
2828+2929+ /// Called after a route is mounted.
3030+ async fn on_post_route(&mut self, _: HookContext<'_>) {}
3131+}
+30
src/module/sync.rs
···11+// This file is part of Windmark <https://github.com/gemrest/windmark>.
22+// Copyright (C) 2022-2022 Fuwn <contact@fuwn.me>
33+//
44+// This program is free software: you can redistribute it and/or modify
55+// it under the terms of the GNU General Public License as published by
66+// the Free Software Foundation, version 3.
77+//
88+// This program is distributed in the hope that it will be useful, but
99+// WITHOUT ANY WARRANTY; without even the implied warranty of
1010+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1111+// General Public License for more details.
1212+//
1313+// You should have received a copy of the GNU General Public License
1414+// along with this program. If not, see <http://www.gnu.org/licenses/>.
1515+//
1616+// Copyright (C) 2022-2022 Fuwn <contact@fuwn.me>
1717+// SPDX-License-Identifier: GPL-3.0-only
1818+1919+use crate::{context::HookContext, Router};
2020+2121+pub trait Module {
2222+ /// Called right after the module is attached.
2323+ fn on_attach(&mut self, _: &mut Router) {}
2424+2525+ /// Called before a route is mounted.
2626+ fn on_pre_route(&mut self, _: HookContext<'_>) {}
2727+2828+ /// Called after a route is mounted.
2929+ fn on_post_route(&mut self, _: HookContext<'_>) {}
3030+}