1use std::borrow::Cow;
7use std::error::Error as StdError;
8use std::fmt::{self, Debug, Display, Formatter};
9
10use sqlx_core::error::*;
11
12pub struct FbError(rsfbclient::FbError);
13
14impl Debug for FbError {
15 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
16 write!(f, "{:?}", self.0)
17 }
18}
19
20impl Display for FbError {
21 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
22 write!(f, "{}", self.0)
23 }
24}
25
26impl StdError for FbError {}
27
28impl DatabaseError for FbError {
29 #[inline]
30 fn message(&self) -> &str {
31 use rsfbclient::FbError as Error;
32 match &self.0 {
33 Error::Sql { msg, .. } => &msg,
34 Error::Io(_) => "io error",
35 Error::Other(msg) => &msg,
36 }
37 }
38
39 #[inline]
40 fn code(&self) -> Option<Cow<'_, str>> {
41 use rsfbclient::FbError as Error;
42 let code = match &self.0 {
43 Error::Sql { code, .. } => *code,
44 Error::Io(e) => e.raw_os_error().unwrap_or(-1),
45 Error::Other(_) => -1,
46 };
47 Some(format!("{}", code).into())
48 }
49
50 fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static) {
51 self
52 }
53
54 fn as_error_mut(&mut self) -> &mut (dyn StdError + Send + Sync + 'static) {
55 self
56 }
57
58 fn into_error(self: Box<Self>) -> Box<dyn StdError + Send + Sync + 'static> {
59 self
60 }
61
62 fn kind(&self) -> ErrorKind {
63 ErrorKind::Other
64 }
65}
66
67impl From<rsfbclient::FbError> for FbError {
68 fn from(error: rsfbclient::FbError) -> Self {
69 Self(error)
70 }
71}