use std::future::Future;
use std::pin::Pin;
use crate::error::ServerManagerError;
use crate::state::ServerState;
pub trait ServerProvider: Send + Sync {
fn start(&self) -> Pin<Box<dyn Future<Output = Result<(), ServerManagerError>> + Send + '_>>;
fn stop(&self) -> Pin<Box<dyn Future<Output = Result<(), ServerManagerError>> + Send + '_>>;
fn check_status(
&self,
) -> Pin<Box<dyn Future<Output = Result<ProviderStatus, ServerManagerError>> + Send + '_>>;
fn provider_type(&self) -> &'static str;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum ProviderStatus {
Running,
Stopped,
Starting,
Stopping,
Unknown,
}
impl From<ProviderStatus> for ServerState {
fn from(status: ProviderStatus) -> Self {
match status {
ProviderStatus::Running => Self::Online,
ProviderStatus::Stopped => Self::Sleeping,
ProviderStatus::Starting => Self::Starting,
ProviderStatus::Stopping => Self::Stopping,
ProviderStatus::Unknown => Self::Unknown,
}
}
}