js_randomness_predictor/
errors.rs1use std::{
2 error::Error,
3 fmt::{Display, Formatter, Result},
4 sync::{MutexGuard, PoisonError},
5};
6
7#[derive(Debug)]
8pub enum InitError {
9 Unsat,
10 MissingModel,
11 EvalFailed(&'static str),
12 ConvertFailed(&'static str),
13}
14
15impl Display for InitError {
16 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
17 use InitError::*;
18 #[allow(clippy::implicit_return)]
19 match self {
20 Unsat => write!(f, "Solver returned UNSAT"),
21 MissingModel => write!(f, "Failed to get model from solver"),
22 EvalFailed(field) => write!(f, "Failed to evaluate {field}"),
23 ConvertFailed(field) => write!(f, "Failed to convert {field} to u64"),
24 }
25 }
26}
27
28impl Error for InitError {}
29
30#[derive(Debug)]
31pub struct PredictionLimitError;
32
33impl Display for PredictionLimitError {
34 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
35 return write!(
36 f,
37 "Prediction count exceeded maximum. 'Initial sequence length' + 'number of predictions' cannot exceed 64! See README for more info!\nPlease call 'reset' with a 'new sequence'! eg. `<instance>.reset(new_sequence)``"
38 );
39 }
40}
41
42impl Error for PredictionLimitError {}
43
44impl From<PoisonError<MutexGuard<'_, u8>>> for PredictionLimitError {
45 fn from(_: PoisonError<MutexGuard<'_, u8>>) -> Self {
46 return PredictionLimitError;
47 }
48}