From cc6a0ada01bcda2ed16995939d9305ea6dc26a3a Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 16 Jan 2021 14:19:14 -0500 Subject: [PATCH] Add back Error::as_db_error Closes #732 --- tokio-postgres/src/error/mod.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tokio-postgres/src/error/mod.rs b/tokio-postgres/src/error/mod.rs index 3df52904..ee29a1db 100644 --- a/tokio-postgres/src/error/mod.rs +++ b/tokio-postgres/src/error/mod.rs @@ -414,14 +414,18 @@ impl Error { self.0.cause } + /// Returns the source of this error if it was a `DbError`. + /// + /// This is a simple convenience method. + pub fn as_db_error(&self) -> Option<&DbError> { + self.source().and_then(|e| e.downcast_ref::()) + } + /// Returns the SQLSTATE error code associated with the error. /// - /// This is a convenience method that downcasts the cause to a `DbError` - /// and returns its code. + /// This is a convenience method that downcasts the cause to a `DbError` and returns its code. pub fn code(&self) -> Option<&SqlState> { - self.source() - .and_then(|e| e.downcast_ref::()) - .map(DbError::code) + self.as_db_error().map(DbError::code) } fn new(kind: Kind, cause: Option>) -> Error {