1use core::fmt;
4
5#[cfg(feature = "std")]
6use std::error::Error;
7
8#[derive(Debug)]
10pub struct InvalidArgumentError {
11 msg: &'static str,
12}
13
14impl fmt::Display for InvalidArgumentError {
15 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
16 write!(f, "InvalidArgumentError: {}", self.msg)
17 }
18}
19
20#[cfg(feature = "std")]
21impl Error for InvalidArgumentError {}
22
23#[derive(Debug)]
25pub struct ModelScaleError {
26 msg: &'static str,
27}
28
29impl fmt::Display for ModelScaleError {
30 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
31 write!(f, "ModelScaleError: {}", self.msg)
32 }
33}
34
35#[cfg(feature = "std")]
36impl Error for ModelScaleError {}
37
38#[derive(Debug)]
40pub enum RucrfError {
41 InvalidArgument(InvalidArgumentError),
43
44 ModelScale(ModelScaleError),
46}
47
48impl RucrfError {
49 pub(crate) const fn invalid_argument(msg: &'static str) -> Self {
51 Self::InvalidArgument(InvalidArgumentError { msg })
52 }
53
54 pub(crate) const fn model_scale(msg: &'static str) -> Self {
56 Self::ModelScale(ModelScaleError { msg })
57 }
58}
59
60impl fmt::Display for RucrfError {
61 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
62 match self {
63 Self::InvalidArgument(e) => e.fmt(f),
64 Self::ModelScale(e) => e.fmt(f),
65 }
66 }
67}
68
69#[cfg(feature = "std")]
70impl Error for RucrfError {}
71
72pub type Result<T, E = RucrfError> = core::result::Result<T, E>;