use core::fmt;
use crate::prelude::*;
use crate::ThresholdError;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ParseThresholdError {
NoChildren,
KNotTerminal,
ParseK(String),
Threshold(ThresholdError),
}
impl fmt::Display for ParseThresholdError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use ParseThresholdError::*;
match *self {
NoChildren => f.write_str("expected threshold, found terminal"),
KNotTerminal => f.write_str("expected positive integer, found expression"),
ParseK(ref x) => write!(f, "failed to parse threshold value {}", x),
Threshold(ref e) => e.fmt(f),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for ParseThresholdError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use ParseThresholdError::*;
match *self {
NoChildren => None,
KNotTerminal => None,
ParseK(..) => None,
Threshold(ref e) => Some(e),
}
}
}