1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::error::Error as StdError;
use std::fmt::{self, Debug, Display, Formatter};

use crate::error::DatabaseError;
use crate::mssql::protocol::error::Error;

/// An error returned from the MSSQL database.
pub struct MssqlDatabaseError(pub(crate) Error);

impl Debug for MssqlDatabaseError {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        f.debug_struct("MssqlDatabaseError")
            .field("message", &self.0.message)
            .field("number", &self.0.number)
            .field("state", &self.0.state)
            .field("class", &self.0.class)
            .field("server", &self.0.server)
            .field("procedure", &self.0.procedure)
            .field("line", &self.0.line)
            .finish()
    }
}

impl Display for MssqlDatabaseError {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        f.pad(self.message())
    }
}

impl StdError for MssqlDatabaseError {}

impl DatabaseError for MssqlDatabaseError {
    #[inline]
    fn message(&self) -> &str {
        &self.0.message
    }

    #[doc(hidden)]
    fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static) {
        self
    }

    #[doc(hidden)]
    fn as_error_mut(&mut self) -> &mut (dyn StdError + Send + Sync + 'static) {
        self
    }

    #[doc(hidden)]
    fn into_error(self: Box<Self>) -> Box<dyn StdError + Send + Sync + 'static> {
        self
    }
}