ex3_common_error_info/
lib.rs

1use std::fmt;
2use std::fmt::{Display, Formatter};
3
4#[cfg(feature = "canister")]
5use candid::CandidType;
6use serde::Deserialize;
7
8#[derive(Debug, Clone, Deserialize)]
9#[cfg_attr(feature = "canister", derive(CandidType))]
10pub struct ErrorInfo {
11    /// Error code
12    pub code: u32,
13    /// Error message
14    pub message: String,
15}
16
17impl PartialEq<Self> for ErrorInfo {
18    fn eq(&self, other: &Self) -> bool {
19        self.code == other.code
20    }
21}
22
23impl Eq for ErrorInfo {}
24
25impl Display for ErrorInfo {
26    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
27        write!(f, "{} {}", self.code, self.message)
28    }
29}