File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -414,14 +414,18 @@ impl Error {
414
414
self . 0 . cause
415
415
}
416
416
417
+ /// Returns the source of this error if it was a `DbError`.
418
+ ///
419
+ /// This is a simple convenience method.
420
+ pub fn as_db_error ( & self ) -> Option < & DbError > {
421
+ self . source ( ) . and_then ( |e| e. downcast_ref :: < DbError > ( ) )
422
+ }
423
+
417
424
/// Returns the SQLSTATE error code associated with the error.
418
425
///
419
- /// This is a convenience method that downcasts the cause to a `DbError`
420
- /// and returns its code.
426
+ /// This is a convenience method that downcasts the cause to a `DbError` and returns its code.
421
427
pub fn code ( & self ) -> Option < & SqlState > {
422
- self . source ( )
423
- . and_then ( |e| e. downcast_ref :: < DbError > ( ) )
424
- . map ( DbError :: code)
428
+ self . as_db_error ( ) . map ( DbError :: code)
425
429
}
426
430
427
431
fn new ( kind : Kind , cause : Option < Box < dyn error:: Error + Sync + Send > > ) -> Error {
You can’t perform that action at this time.
0 commit comments