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
//! Error type for sprs

use std::error::Error;
use std::fmt;

#[derive(PartialEq, Debug)]
pub enum SprsError {
    NonSortedIndices,
    UnsortedIndptr,
    SingularMatrix,
}

use self::SprsError::*;

impl SprsError {
    fn descr(&self) -> &str {
        match *self {
            NonSortedIndices => "a vector's indices are not sorted",
            UnsortedIndptr => "indptr is not sorted",
            SingularMatrix => "matrix is singular",
        }
    }
}

impl Error for SprsError {
    fn description(&self) -> &str {
        self.descr()
    }
}

impl fmt::Display for SprsError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        self.descr().fmt(f)
    }
}