use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug, Clone, PartialEq)]
pub enum Error {
#[error("infeasible: {0}")]
Infeasible(String),
#[error("unbounded: {0}")]
Unbounded(String),
#[error("invalid input: {0}")]
InvalidInput(String),
#[error("dimension mismatch: expected {expected}, got {got}")]
DimensionMismatch {
expected: usize,
got: usize,
},
#[error("timeout after {seconds} seconds")]
Timeout {
seconds: f64,
},
#[error("numeric overflow: {0}")]
Overflow(String),
#[error("did not converge after {iterations} iterations")]
NoConvergence {
iterations: usize,
},
#[error("FFI feature required for {0}")]
FfiRequired(String),
#[error("internal error: {0}")]
Internal(String),
}
impl Error {
pub fn infeasible(msg: impl Into<String>) -> Self {
Self::Infeasible(msg.into())
}
pub fn invalid_input(msg: impl Into<String>) -> Self {
Self::InvalidInput(msg.into())
}
pub fn dimension_mismatch(expected: usize, got: usize) -> Self {
Self::DimensionMismatch { expected, got }
}
pub fn timeout(seconds: f64) -> Self {
Self::Timeout { seconds }
}
}