1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum YieldCurveError {
6 InsufficientData {
8 method: &'static str,
9 need: usize,
10 got: usize,
11 },
12 InvalidPoint(String),
14 FitFailed(String),
17 InvalidTimeRange(String),
21}
22
23impl fmt::Display for YieldCurveError {
24 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25 match self {
26 Self::InsufficientData { method, need, got } => {
27 write!(f, "{method} requires at least {need} points, got {got}")
28 }
29 Self::InvalidPoint(msg) => write!(f, "invalid point: {msg}"),
30 Self::FitFailed(msg) => write!(f, "fit failed to converge: {msg}"),
31 Self::InvalidTimeRange(msg) => write!(f, "invalid time range: {msg}"),
32 }
33 }
34}
35
36impl std::error::Error for YieldCurveError {}