oxidd_core/
error.rs

1//! Error types
2
3use std::{fmt, ops::Range};
4
5use crate::VarNo;
6
7/// Out of memory error
8#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
9pub struct OutOfMemory;
10
11impl fmt::Display for OutOfMemory {
12    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13        f.write_str("decision diagram operation ran out of memory")
14    }
15}
16impl std::error::Error for OutOfMemory {}
17
18impl From<OutOfMemory> for std::io::Error {
19    fn from(_: OutOfMemory) -> Self {
20        std::io::ErrorKind::OutOfMemory.into()
21    }
22}
23
24/// Error details for labelling a variable with a name that is already in use
25#[derive(Clone, PartialEq, Eq, Hash, Debug)]
26pub struct DuplicateVarName {
27    /// The variable name
28    pub name: String,
29    /// Variable number already using the name
30    pub present_var: VarNo,
31    /// Range of variables that have been successfully added before the error
32    /// occurred
33    pub added_vars: Range<VarNo>,
34}
35
36impl fmt::Display for DuplicateVarName {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        write!(
39            f,
40            "the variable name '{}' is already in use for variable number {}",
41            self.name, self.present_var
42        )
43    }
44}