1use num_enum::{TryFromPrimitive, TryFromPrimitiveError};
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum StarTrustError {
6 #[error("IoError: {0}")]
7 IoError(std::io::Error),
8 #[error("GameStateError: {0}")]
9 GameStateError(String),
10 #[error("ParseFloatError: {0}")]
11 ParseFloatError(std::num::ParseFloatError),
12 #[error("ParseIntError: {0}")]
13 ParseIntError(std::num::ParseIntError),
14 #[error("TryFromPrimitiveError")]
15 TryFromPrimitiveError(String),
16 #[error("GeneralError: {0}")]
17 GeneralError(String),
18}
19
20impl From<std::io::Error> for StarTrustError {
21 fn from(value: std::io::Error) -> Self {
22 StarTrustError::IoError(value)
23 }
24}
25
26impl From<std::num::ParseFloatError> for StarTrustError {
27 fn from(value: std::num::ParseFloatError) -> Self {
28 StarTrustError::ParseFloatError(value)
29 }
30}
31
32impl From<std::num::ParseIntError> for StarTrustError {
33 fn from(value: std::num::ParseIntError) -> Self {
34 StarTrustError::ParseIntError(value)
35 }
36}
37
38impl<T: TryFromPrimitive> From<TryFromPrimitiveError<T>> for StarTrustError {
39 fn from(value: TryFromPrimitiveError<T>) -> Self {
40 StarTrustError::TryFromPrimitiveError(format!("{}", value))
41 }
42}
43
44pub type StResult<T> = std::result::Result<T, StarTrustError>;
45
46