1use std::error::Error;
4use std::fmt;
5use std::result;
6
7pub mod momentum;
8pub mod trend;
9
10pub type Result<T> = result::Result<T, AnalysisError>;
15
16#[derive(Debug)]
18pub enum AnalysisError {
19 GainLessThanZero,
21 LossLessThanZero,
23 CloseGreaterThanHigh,
25 CloseLessThanLow,
27 HighLessThanLow,
29 SliceIsEmpty,
31}
32
33impl fmt::Display for AnalysisError {
34 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
35 write!(f, "error: {}", self.description())
36 }
37}
38
39impl Error for AnalysisError {
40 fn description(&self) -> &str {
41 match *self {
42 AnalysisError::GainLessThanZero => "gain < 0",
43 AnalysisError::LossLessThanZero => "loss < 0",
44 AnalysisError::CloseGreaterThanHigh => "close > high",
45 AnalysisError::CloseLessThanLow => "close < low",
46 AnalysisError::HighLessThanLow => "high < low",
47 AnalysisError::SliceIsEmpty => "slice is empty",
48 }
49 }
50
51 fn cause(&self) -> Option<&Error> {
52 None
53 }
54}