Skip to main content

solve/
error.rs

1//! Error type for SOLVE score construction.
2
3use core::fmt;
4
5/// Failure to construct a value that the SOLVE specification bounds.
6#[derive(Debug, Clone, Copy, PartialEq)]
7#[non_exhaustive]
8pub enum SolveError {
9    /// A score fell outside the specification's `0.0..=10.0` range.
10    OutOfRange {
11        /// The rejected value.
12        value: f64,
13    },
14    /// A score was NaN or infinite.
15    NotFinite {
16        /// The rejected value.
17        value: f64,
18    },
19}
20
21impl fmt::Display for SolveError {
22    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23        match self {
24            Self::OutOfRange { value } => {
25                write!(f, "score {value} is outside the SOLVE range 0.0..=10.0")
26            }
27            Self::NotFinite { value } => write!(f, "score {value} is not finite"),
28        }
29    }
30}
31
32impl core::error::Error for SolveError {}