use crate::task::TaskBuilder;
use crate::version::Version;
use async_trait::async_trait;
use crate::command::CommandBuilder;
use std::fmt;
use std::path::PathBuf;
use crate::server::ServerType;
use crate::config::Config;
#[async_trait]
pub trait PluginBuilder: Send + Sync + 'static {
fn name(&self) -> &'static str;
fn version(&self) -> Version;
fn abi_version(&self) -> Version;
fn description(&self) -> &'static str;
fn author(&self) -> &'static str;
fn tasks(&self) -> Vec<Box<dyn TaskBuilder>>;
fn commands(&self) -> Vec<Box<dyn CommandBuilder>>;
fn config(&self) -> Option<Vec<Box<dyn Config>>> {
None
}
fn server(&self) -> Option<ServerType> {
None
}
async fn init(&self) -> Result<(), Box<dyn std::error::Error>>;
}
#[derive(Debug, Clone)]
pub struct Plugin {
pub name: String,
pub version: String,
pub author: String,
}
#[derive(Clone)]
pub enum PluginType {
Path(PathBuf),
Builder(&'static dyn PluginBuilder),
}
impl fmt::Debug for PluginType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PluginType::Path(path) => f.debug_struct("Path").field("path", path).finish(),
PluginType::Builder(_) => f.debug_struct("Builder").finish(),
}
}
}
impl From<PathBuf> for PluginType {
fn from(path: PathBuf) -> Self {
PluginType::Path(path)
}
}
impl From<&'static dyn PluginBuilder> for PluginType {
fn from(builder: &'static dyn PluginBuilder) -> Self {
PluginType::Builder(builder)
}
}
#[derive(Debug, Clone)]
pub enum PluginId {
Index(u64),
Name(String),
}
impl From<u64> for PluginId {
fn from(value: u64) -> Self {
Self::Index(value)
}
}
impl From<String> for PluginId {
fn from(value: String) -> Self {
Self::Name(value)
}
}
impl From<&str> for PluginId {
fn from(value: &str) -> Self {
Self::Name(value.to_string())
}
}