pub trait ResultExt<T> {
// Required method
fn with_query<F>(self, ctx: F) -> Result<T>
where F: FnOnce() -> QueryContext;
}Expand description
Adds the failing query’s SQL and parameters to an error.
§Examples
use drizzle_core::error::{DrizzleError, QueryContext, ResultExt};
let result: Result<(), DrizzleError> = Err(DrizzleError::NotFound);
let error = result
.with_query(|| QueryContext::new("SELECT * FROM users WHERE id = ?", &[&7]))
.unwrap_err();
assert_eq!(
error.to_string(),
"No rows found\n sql: SELECT * FROM users WHERE id = ?\n params: [7]",
);Required Methods§
Sourcefn with_query<F>(self, ctx: F) -> Result<T>where
F: FnOnce() -> QueryContext,
fn with_query<F>(self, ctx: F) -> Result<T>where
F: FnOnce() -> QueryContext,
On error, wraps it in DrizzleError::QueryFailed with the context
from ctx. ctx only runs on the error path, and an error that
already has context keeps it.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".