use async_trait::async_trait;
use crate::error::Result;
pub trait Convert<T> {
fn convert(&self) -> T;
}
pub trait CloneInto<T: Clone> {
fn clone_into(&self) -> T;
}
pub trait Initialize {
fn initialize(&mut self) -> Result<()>;
}
pub trait Validate {
fn validate(&self) -> Result<()>;
}
pub trait Lifecycle {
fn start(&mut self) -> Result<()>;
fn stop(&mut self) -> Result<()>;
fn restart(&mut self) -> Result<()>;
}
#[async_trait]
pub trait AsyncLifecycle {
async fn start(&mut self) -> Result<()>;
async fn stop(&mut self) -> Result<()>;
async fn restart(&mut self) -> Result<()>;
}
pub trait Serializer {
fn to_bytes(&self) -> Result<Vec<u8>>;
fn from_bytes(bytes: &[u8]) -> Result<Self>
where
Self: Sized;
}
pub trait CloneBox {
fn clone_box(&self) -> Box<dyn CloneBox>;
}
impl<T> CloneBox for T
where
T: 'static + Clone,
{
fn clone_box(&self) -> Box<dyn CloneBox> {
Box::new(self.clone())
}
}
pub trait Identifier {
fn id(&self) -> String;
}
pub trait Named {
fn name(&self) -> String;
}
pub trait Described {
fn description(&self) -> String;
}
pub trait Versioned {
fn version(&self) -> String;
}
pub trait State {
fn state(&self) -> String;
fn is_available(&self) -> bool;
}
pub trait Tagged {
fn tags(&self) -> Vec<String>;
fn add_tag(&mut self, tag: String);
fn remove_tag(&mut self, tag: &str);
fn has_tag(&self, tag: &str) -> bool;
}