use std::{future::Future, pin::Pin};
use super::super::context::ComponentInteractionContext;
use crate::Error;
pub(crate) type ComponentInteractionFunc<T> =
fn(ComponentInteractionContext<T>) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>;
#[derive(Clone)]
pub struct ComponentInteractionHandler<T: Clone + Send + Sync> {
pub module: String,
pub custom_id: String,
pub func: ComponentInteractionFunc<T>,
}
impl<T: Clone + Send + Sync> ComponentInteractionHandler<T> {
#[tracing::instrument(name="component-interaction-handler", skip_all, fields(
module=self.module,
custom_id=self.custom_id
))]
pub async fn run(&self, ctx: ComponentInteractionContext<T>) -> Result<(), Error> {
(self.func)(ctx).await
}
}