use std::error::Error;
use std::fmt;
use std::result;
pub mod momentum;
pub mod trend;
pub type Result<T> = result::Result<T, AnalysisError>;
#[derive(Debug)]
pub enum AnalysisError {
GainLessThanZero,
LossLessThanZero,
CloseGreaterThanHigh,
CloseLessThanLow,
HighLessThanLow,
SliceIsEmpty,
}
impl fmt::Display for AnalysisError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "error: {}", self.description())
}
}
impl Error for AnalysisError {
fn description(&self) -> &str {
match *self {
AnalysisError::GainLessThanZero => "gain < 0",
AnalysisError::LossLessThanZero => "loss < 0",
AnalysisError::CloseGreaterThanHigh => "close > high",
AnalysisError::CloseLessThanLow => "close < low",
AnalysisError::HighLessThanLow => "high < low",
AnalysisError::SliceIsEmpty => "slice is empty",
}
}
fn cause(&self) -> Option<&Error> {
None
}
}