use crate::request::ReqCtx;
use crate::response::ApiResponse;
use serde_json::Value;
use std::future::Future;
use std::pin::Pin;
pub type ActionFuture = Pin<Box<dyn Future<Output = ApiResponse> + Send>>;
pub type ActionHandler = fn(ReqCtx, String, Value) -> ActionFuture;
pub struct CustomAction {
pub name: &'static str,
pub label: Option<&'static str>,
pub handler: ActionHandler,
}
impl CustomAction {
pub fn new(name: &'static str, handler: ActionHandler) -> Self {
Self {
name,
label: None,
handler,
}
}
pub fn labeled(name: &'static str, label: &'static str, handler: ActionHandler) -> Self {
Self {
name,
label: Some(label),
handler,
}
}
pub fn display_label(&self) -> &'static str {
self.label.unwrap_or(self.name)
}
}