miniscript/expression/
error.rs1use core::fmt;
6
7use crate::prelude::*;
8use crate::ThresholdError;
9
10#[derive(Clone, Debug, PartialEq, Eq)]
12pub enum ParseThresholdError {
13 NoChildren,
15 KNotTerminal,
17 ParseK(String),
21 Threshold(ThresholdError),
23}
24
25impl fmt::Display for ParseThresholdError {
26 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27 use ParseThresholdError::*;
28
29 match *self {
30 NoChildren => f.write_str("expected threshold, found terminal"),
31 KNotTerminal => f.write_str("expected positive integer, found expression"),
32 ParseK(ref x) => write!(f, "failed to parse threshold value {}", x),
33 Threshold(ref e) => e.fmt(f),
34 }
35 }
36}
37
38#[cfg(feature = "std")]
39impl std::error::Error for ParseThresholdError {
40 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
41 use ParseThresholdError::*;
42
43 match *self {
44 NoChildren => None,
45 KNotTerminal => None,
46 ParseK(..) => None,
47 Threshold(ref e) => Some(e),
48 }
49 }
50}