1pub trait IntoStdError {
3 fn into_std_error(self) -> cosmwasm_std::StdError;
18}
19
20impl<T> IntoStdError for T
21where
22 T: storey::error::StoreyError,
23{
24 fn into_std_error(self) -> cosmwasm_std::StdError {
25 cosmwasm_std::StdError::generic_err(self.to_string())
26 }
27}
28
29#[cfg(test)]
30mod tests {
31 use cosmwasm_std::StdError;
32 use storey::error::StoreyError;
33
34 use super::*;
35
36 #[derive(Debug)]
37 struct MockError {
38 msg: String,
39 }
40
41 impl std::fmt::Display for MockError {
42 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43 write!(f, "{}", self.msg)
44 }
45 }
46
47 impl StoreyError for MockError {}
48
49 #[test]
50 fn test_into_std_error() {
51 let error = MockError {
52 msg: "An error occurred".to_string(),
53 };
54 let std_error: StdError = error.into_std_error();
55 assert_eq!(std_error, StdError::generic_err("An error occurred"));
56 }
57}