De-duplicate error impls and forward MySqlConnection/PgConnection to crate root

This commit is contained in:
Ryan Leckey
2019-12-27 20:55:30 -08:00
parent 7d745f98ea
commit 017ee38725
5 changed files with 61 additions and 82 deletions

View File

@@ -1,9 +1,9 @@
use crate::error::DatabaseError;
use crate::postgres::protocol::Response;
use std::fmt::{self, Debug, Display};
pub struct PgError(pub(super) Box<Response>);
impl crate::error::DatabaseError for PgError {
impl DatabaseError for PgError {
fn message(&self) -> &str {
&self.0.message
}
@@ -29,25 +29,4 @@ impl crate::error::DatabaseError for PgError {
}
}
impl Debug for PgError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use crate::error::DatabaseError;
f.debug_struct("DatabaseError")
.field("message", &self.message())
.field("details", &self.details())
.field("hint", &self.hint())
.field("table_name", &self.table_name())
.field("column_name", &self.column_name())
.field("constraint_name", &self.constraint_name())
.finish()
}
}
impl Display for PgError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use crate::error::DatabaseError;
f.pad(self.message())
}
}
impl_fmt_error!(PgError);