36 lines
819 B
Rust
36 lines
819 B
Rust
use std::fmt::{Display, Formatter};
|
|
use std::ops::Deref;
|
|
|
|
use thiserror::Error;
|
|
|
|
use bank::account::AccountError;
|
|
|
|
#[derive(Debug, Error)]
|
|
pub struct SocketAccountError(pub AccountError);
|
|
|
|
impl Display for SocketAccountError {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
write!(f, "{}", self.deref())
|
|
}
|
|
}
|
|
|
|
impl Deref for SocketAccountError {
|
|
type Target = AccountError;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.0
|
|
}
|
|
}
|
|
|
|
impl From<SocketAccountError> for u8 {
|
|
fn from(e: SocketAccountError) -> Self {
|
|
match e.deref() {
|
|
AccountError::Overdraw => 11,
|
|
AccountError::Inactive => 12,
|
|
AccountError::InvalidAmount => 13,
|
|
AccountError::NotFound => 14,
|
|
AccountError::AccountNotZero => 15,
|
|
}
|
|
}
|
|
}
|