semantic_commands/
command.rs

1use std::{any::Any, future::Future, pin::Pin, sync::Arc};
2
3type Executor<C> = Box<dyn Fn(Arc<C>) -> Pin<Box<dyn Future<Output = Box<dyn Any + Send>> + Send>> + Send + Sync>;
4
5pub struct Command<C> {
6	pub name: String,
7	pub requires_confirmation: bool,
8	pub executor: Executor<C>,
9}
10
11pub fn async_executor<C, F, Fut, R>(f: F) -> Executor<C>
12where
13	F: Fn(Arc<C>) -> Fut + Send + Sync + 'static,
14	Fut: Future<Output = R> + Send + 'static,
15	R: Any + Send + 'static,
16{
17	Box::new(move |ctx: Arc<C>| {
18		let fut = f(ctx);
19		Box::pin(async move { Box::new(fut.await) as Box<dyn Any + Send> })
20	})
21}