Skip to main content

rbdc_oracle/
error.rs

1use std::error::Error as StdError;
2use std::fmt::{self, Display, Formatter};
3
4#[derive(Debug, Clone, Eq, PartialEq)]
5pub struct OracleError {
6    message: String,
7}
8
9impl OracleError {
10    pub fn new(message: impl Into<String>) -> Self {
11        Self {
12            message: message.into(),
13        }
14    }
15
16    pub fn message(&self) -> &str {
17        &self.message
18    }
19}
20
21impl Display for OracleError {
22    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
23        f.pad(&self.message)
24    }
25}
26
27impl StdError for OracleError {}
28
29impl From<oracle::Error> for OracleError {
30    fn from(value: oracle::Error) -> Self {
31        Self::new(value.to_string())
32    }
33}
34
35impl From<OracleError> for rbdc::Error {
36    fn from(value: OracleError) -> Self {
37        Self::from(value.to_string())
38    }
39}