pub trait DatabaseError:
'static
+ Send
+ Sync
+ StdError {
// Required method
fn message(&self) -> &str;
// Provided methods
fn code(&self) -> Option<Cow<'_, str>> { ... }
fn offset(&self) -> Option<usize> { ... }
fn constraint(&self) -> Option<&str> { ... }
}
Expand description
An error that was returned from the database.
Required Methods§
Provided Methods§
Sourcefn offset(&self) -> Option<usize>
fn offset(&self) -> Option<usize>
The byte offset in the query string where the error occurred, if applicable
Sourcefn constraint(&self) -> Option<&str>
fn constraint(&self) -> Option<&str>
Returns the name of the constraint that triggered the error, if applicable. If the error was caused by a conflict of a unique index, this will be the index name.
§Note
Currently only populated by the Postgres driver.
Implementations§
Source§impl dyn DatabaseError
impl dyn DatabaseError
Sourcepub fn downcast_ref<E: DatabaseError>(&self) -> &E
pub fn downcast_ref<E: DatabaseError>(&self) -> &E
Downcast a reference to this generic database error to a specific database error type.
§Panics
Panics if the database error type is not E
. This is a deliberate contrast from
Error::downcast_ref
which returns Option<&E>
. In normal usage, you should know the
specific error type. In other cases, use try_downcast_ref
.
Sourcepub fn downcast<E: DatabaseError>(self: Box<Self>) -> Box<E>
pub fn downcast<E: DatabaseError>(self: Box<Self>) -> Box<E>
Downcast this generic database error to a specific database error type.
§Panics
Panics if the database error type is not E
. This is a deliberate contrast from
Error::downcast
which returns Option<E>
. In normal usage, you should know the
specific error type. In other cases, use try_downcast
.
Sourcepub fn try_downcast_ref<E: DatabaseError>(&self) -> Option<&E>
pub fn try_downcast_ref<E: DatabaseError>(&self) -> Option<&E>
Downcast a reference to this generic database error to a specific database error type.
Sourcepub fn try_downcast<E: DatabaseError>(
self: Box<Self>,
) -> StdResult<Box<E>, Box<Self>>
pub fn try_downcast<E: DatabaseError>( self: Box<Self>, ) -> StdResult<Box<E>, Box<Self>>
Downcast this generic database error to a specific database error type.
Trait Implementations§
Source§impl Error for Box<dyn DatabaseError>
impl Error for Box<dyn DatabaseError>
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Implementors§
impl DatabaseError for MssqlDatabaseError
mssql
only.impl DatabaseError for MySqlDatabaseError
mysql
only.impl DatabaseError for PgDatabaseError
postgres
only.impl DatabaseError for SqliteError
sqlite
only.