Skip to main content

sim_lib_discrete_rank/
error.rs

1//! Error type for the discrete rank adapters.
2
3use sim_lib_discrete_comb::CombError;
4use sim_lib_discrete_graph::GraphError;
5use sim_lib_discrete_spectral::SpectralError;
6
7/// Errors raised by discrete rank spaces, metrics, and grade compilers.
8#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
9pub enum RankAdapterError {
10    /// A staged rank adapter is not yet implemented.
11    #[error("unsupported: {0}")]
12    Unsupported(String),
13    /// A rank / unrank round-trip invariant was violated.
14    #[error("round-trip failure: {0}")]
15    RoundTrip(String),
16    /// An explicit enumeration or search limit was exceeded.
17    #[error("limit exceeded: {0}")]
18    LimitExceeded(String),
19    /// A value was invalid for the space (wrong shape, out of range, etc.).
20    #[error("invalid value: {0}")]
21    Invalid(String),
22}
23
24impl From<CombError> for RankAdapterError {
25    fn from(err: CombError) -> Self {
26        RankAdapterError::Invalid(err.to_string())
27    }
28}
29
30impl From<GraphError> for RankAdapterError {
31    fn from(err: GraphError) -> Self {
32        RankAdapterError::Invalid(err.to_string())
33    }
34}
35
36impl From<SpectralError> for RankAdapterError {
37    fn from(err: SpectralError) -> Self {
38        RankAdapterError::Invalid(err.to_string())
39    }
40}