use crate::StorageError;
use std::fmt;
#[derive(Debug)]
pub enum ObjectiveError {
Pruned,
Failed(Box<dyn std::error::Error + Send + Sync>),
}
impl ObjectiveError {
pub fn pruned() -> Self {
ObjectiveError::Pruned
}
}
impl fmt::Display for ObjectiveError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ObjectiveError::Pruned => write!(f, "trial pruned"),
ObjectiveError::Failed(e) => write!(f, "objective failed: {e}"),
}
}
}
impl<E> From<E> for ObjectiveError
where
E: std::error::Error + Send + Sync + 'static,
{
fn from(e: E) -> Self {
ObjectiveError::Failed(Box::new(e))
}
}
pub type ObjectiveResult = Result<f64, ObjectiveError>;
#[derive(Debug)]
pub enum HyperoptError {
Storage(StorageError),
}
impl fmt::Display for HyperoptError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
HyperoptError::Storage(e) => write!(f, "{e}"),
}
}
}
impl std::error::Error for HyperoptError {}
impl From<StorageError> for HyperoptError {
fn from(e: StorageError) -> Self {
HyperoptError::Storage(e)
}
}