use crate::{response::ResponseData, server::ServerContext}; use async_trait::async_trait; use core::fmt::Debug; use std::{ fmt::{self, Display}, sync::Arc, }; mod connect; mod disconnect; mod status; pub use connect::Connect; pub use disconnect::Disconnect; pub use status::GetStatus; #[derive(Debug)] pub(crate) struct CommandContext { server_context: Arc, } impl From> for CommandContext { fn from(server_context: Arc) -> Self { Self { server_context } } } #[derive(Debug)] pub(crate) struct CommandError { message: String, } impl From for CommandError { fn from(message: String) -> Self { Self { message } } } impl Display for CommandError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "CommandError {:#?}", self.message) } } #[async_trait] pub(crate) trait Command: Send + Sync { async fn handle(&self, context: CommandContext) -> Result; } impl Debug for dyn Command { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Command") } }