tulpje_framework/handler/
command_handler.rs

1use std::{future::Future, pin::Pin};
2
3use super::super::context::CommandContext;
4
5use crate::Error;
6
7pub(crate) type CommandFunc<T> =
8    fn(CommandContext<T>) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>;
9
10#[derive(Clone)]
11pub struct CommandHandler<T: Clone + Send + Sync> {
12    pub module: String,
13    pub name: String,
14    pub func: CommandFunc<T>,
15}
16
17impl<T: Clone + Send + Sync> CommandHandler<T> {
18    pub async fn run(&self, ctx: CommandContext<T>) -> Result<(), Error> {
19        // can add more handling/parsing/etc here in the future
20        (self.func)(ctx).await
21    }
22}