Add back Error::as_db_error

Closes #732
This commit is contained in:
Steven Fackler
2021-01-16 14:19:14 -05:00
parent 096f4f59c8
commit cc6a0ada01

View File

@@ -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::<DbError>())
}
/// 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::<DbError>())
.map(DbError::code)
self.as_db_error().map(DbError::code)
}
fn new(kind: Kind, cause: Option<Box<dyn error::Error + Sync + Send>>) -> Error {