converge_optimization/
error.rs1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Error, Debug, Clone, PartialEq)]
10pub enum Error {
11 #[error("infeasible: {0}")]
13 Infeasible(String),
14
15 #[error("unbounded: {0}")]
17 Unbounded(String),
18
19 #[error("invalid input: {0}")]
21 InvalidInput(String),
22
23 #[error("dimension mismatch: expected {expected}, got {got}")]
25 DimensionMismatch {
26 expected: usize,
28 got: usize,
30 },
31
32 #[error("timeout after {seconds} seconds")]
34 Timeout {
35 seconds: f64,
37 },
38
39 #[error("numeric overflow: {0}")]
41 Overflow(String),
42
43 #[error("did not converge after {iterations} iterations")]
45 NoConvergence {
46 iterations: usize,
48 },
49
50 #[error("FFI feature required for {0}")]
52 FfiRequired(String),
53
54 #[error("internal error: {0}")]
56 Internal(String),
57}
58
59impl Error {
60 pub fn infeasible(msg: impl Into<String>) -> Self {
62 Self::Infeasible(msg.into())
63 }
64
65 pub fn invalid_input(msg: impl Into<String>) -> Self {
67 Self::InvalidInput(msg.into())
68 }
69
70 pub fn dimension_mismatch(expected: usize, got: usize) -> Self {
72 Self::DimensionMismatch { expected, got }
73 }
74
75 pub fn timeout(seconds: f64) -> Self {
77 Self::Timeout { seconds }
78 }
79}