use alloc::string::String;
use core::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SwarmError {
Agent(String),
Scheduler(String),
Memory(String),
Channel(String),
Configuration(String),
ResourceExhausted(String),
Network(String),
Timeout(String),
InvalidState(String),
NotFound(String),
}
impl fmt::Display for SwarmError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
SwarmError::Agent(msg) => write!(f, "Agent error: {}", msg),
SwarmError::Scheduler(msg) => write!(f, "Scheduler error: {}", msg),
SwarmError::Memory(msg) => write!(f, "Memory error: {}", msg),
SwarmError::Channel(msg) => write!(f, "Channel error: {}", msg),
SwarmError::Configuration(msg) => write!(f, "Configuration error: {}", msg),
SwarmError::ResourceExhausted(msg) => write!(f, "Resource exhausted: {}", msg),
SwarmError::Network(msg) => write!(f, "Network error: {}", msg),
SwarmError::Timeout(msg) => write!(f, "Timeout: {}", msg),
SwarmError::InvalidState(msg) => write!(f, "Invalid state: {}", msg),
SwarmError::NotFound(msg) => write!(f, "Not found: {}", msg),
}
}
}
impl SwarmError {
pub fn agent<S: Into<String>>(msg: S) -> Self {
Self::Agent(msg.into())
}
pub fn scheduler<S: Into<String>>(msg: S) -> Self {
Self::Scheduler(msg.into())
}
pub fn memory<S: Into<String>>(msg: S) -> Self {
Self::Memory(msg.into())
}
pub fn channel<S: Into<String>>(msg: S) -> Self {
Self::Channel(msg.into())
}
pub fn config<S: Into<String>>(msg: S) -> Self {
Self::Configuration(msg.into())
}
pub fn resource_exhausted<S: Into<String>>(msg: S) -> Self {
Self::ResourceExhausted(msg.into())
}
pub fn network<S: Into<String>>(msg: S) -> Self {
Self::Network(msg.into())
}
pub fn timeout<S: Into<String>>(msg: S) -> Self {
Self::Timeout(msg.into())
}
pub fn invalid_state<S: Into<String>>(msg: S) -> Self {
Self::InvalidState(msg.into())
}
pub fn not_found<S: Into<String>>(msg: S) -> Self {
Self::NotFound(msg.into())
}
}