rush_sync_server/commands/command.rs
1// =====================================================
2// FILE: commands/command.rs - EINFACHES OBJECT-SAFE TRAIT
3// =====================================================
4
5use crate::core::prelude::*;
6use std::future::Future;
7use std::pin::Pin;
8
9/// ✅ OBJECT-SAFE Command Trait - Box<dyn Command> funktioniert perfekt!
10pub trait Command: Send + Sync + std::fmt::Debug + 'static {
11 /// Command Name für Registry
12 fn name(&self) -> &'static str;
13
14 /// Command Beschreibung
15 fn description(&self) -> &'static str;
16
17 /// Prüft ob Command matched
18 fn matches(&self, command: &str) -> bool;
19
20 /// Synchrone Ausführung
21 fn execute_sync(&self, args: &[&str]) -> Result<String>;
22
23 /// ✅ OBJECT-SAFE: Asynchrone Ausführung mit Pin<Box<...>>
24 fn execute_async<'a>(
25 &'a self,
26 args: &'a [&'a str],
27 ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'a>> {
28 // Default: Ruft sync Version auf
29 Box::pin(async move { self.execute_sync(args) })
30 }
31
32 /// Unterstützt async?
33 fn supports_async(&self) -> bool {
34 false
35 }
36
37 /// Priorität für Command-Matching (höher = wird zuerst geprüft)
38 fn priority(&self) -> u8 {
39 50
40 }
41
42 /// Ist Command verfügbar?
43 fn is_available(&self) -> bool {
44 true
45 }
46}