1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#[derive(Debug, Eq, PartialEq)]
pub enum Error {
FromAPI(String, i32),
NulError(std::ffi::NulError),
ModelObjectRemoved,
ModelObjectPending,
ModelObjectMismatch,
ModelUpdateNeeded,
AlgebraicError(String),
NotYetSupported(String),
}
impl From<std::ffi::NulError> for Error {
fn from(err: std::ffi::NulError) -> Error {
Error::NulError(err)
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Error::FromAPI(message, code) => write!(f, "Error from API: {} ({})", message, code),
Error::NulError(err) => f.write_fmt(format_args!("NulError: {}", err)),
Error::ModelObjectRemoved => {
f.write_str("Variable or constraint has been removed from the model")
}
Error::ModelObjectPending => {
f.write_str("Variable or constraint is awaiting model update")
}
Error::ModelObjectMismatch => {
f.write_str("Variable or constraint is part of a different model")
}
Error::ModelUpdateNeeded => f.write_str(
"Variables or constraints have been added/removed. Call model.update() first.",
),
Error::AlgebraicError(s) => f.write_fmt(format_args!("Algebraic error: {}", s)),
Error::NotYetSupported(s) => f.write_fmt(format_args!("Not yet supported: {}", s)),
}
}
}
impl std::error::Error for Error {}
pub type Result<T> = std::result::Result<T, Error>;