forked from transact-rs/sqlx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.rs
More file actions
49 lines (39 loc) · 1.11 KB
/
Copy pathdatabase.rs
File metadata and controls
49 lines (39 loc) · 1.11 KB
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
use std::error::Error as StdError;
use std::fmt::{self, Display, Formatter};
use sqlx_core::{DatabaseError, Error};
use crate::PgNotice;
/// An error returned from the PostgreSQL database.
///
/// In PostgreSQL, an error is a [`PgNotice`] with a severity
/// at [`Error`][crate::PgNoticeSeverity::Error] or higher.
///
#[derive(Debug)]
pub struct PgDatabaseError(pub(crate) PgNotice);
impl Display for PgDatabaseError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl StdError for PgDatabaseError {}
impl DatabaseError for PgDatabaseError {
fn message(&self) -> &str {
self.0.message()
}
#[inline(always)]
fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static) {
self
}
#[inline(always)]
fn as_error_mut(&mut self) -> &mut (dyn StdError + Send + Sync + 'static) {
self
}
#[inline(always)]
fn into_error(self: Box<Self>) -> Box<dyn StdError + Send + Sync + 'static> {
self
}
}
impl From<PgDatabaseError> for Error {
fn from(err: PgDatabaseError) -> Self {
Self::database(err)
}
}