Skip to main content

ResultExt

Trait ResultExt 

Source
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§

Source

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".

Implementations on Foreign Types§

Source§

impl<T, E> ResultExt<T> for Result<T, E>
where E: Into<DrizzleError>,

Source§

fn with_query<F>(self, ctx: F) -> Result<T>
where F: FnOnce() -> QueryContext,

Implementors§