forked from transact-rs/sqlx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.rs
More file actions
43 lines (33 loc) 路 932 Bytes
/
Copy patherror.rs
File metadata and controls
43 lines (33 loc) 路 932 Bytes
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
use std::fmt::{self, Display};
use crate::error::DatabaseError;
use crate::postgres::protocol::Response;
#[derive(Debug)]
pub struct PgError(pub(super) Response);
impl DatabaseError for PgError {
fn message(&self) -> &str {
&self.0.message
}
fn code(&self) -> Option<&str> {
Some(&self.0.code)
}
fn details(&self) -> Option<&str> {
self.0.detail.as_ref().map(|s| &**s)
}
fn hint(&self) -> Option<&str> {
self.0.hint.as_ref().map(|s| &**s)
}
fn table_name(&self) -> Option<&str> {
self.0.table.as_ref().map(|s| &**s)
}
fn column_name(&self) -> Option<&str> {
self.0.column.as_ref().map(|s| &**s)
}
fn constraint_name(&self) -> Option<&str> {
self.0.constraint.as_ref().map(|s| &**s)
}
}
impl Display for PgError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad(self.message())
}
}