QueryResultExt

Trait QueryResultExt 

Source
pub trait QueryResultExt<T> {
    // Required method
    fn downcast_err<E: Error + Send + Sync + 'static>(
        self,
    ) -> Result<Result<Arc<T>, TypedErr<E>>, QueryError>;
}
Expand description

Extension trait for query results that provides ergonomic error downcasting.

This trait is implemented for Result<Arc<T>, QueryError> and allows you to downcast user errors to a specific type while propagating system errors.

§Example

use query_flow::QueryResultExt;

// Downcast to MyError, propagating system errors and non-matching user errors
let result = db.query(MyQuery::new()).downcast_err::<MyError>()?;

match result {
    Ok(value) => println!("Success: {:?}", value),
    Err(my_err) => println!("MyError: {}", my_err.code),
}

Required Methods§

Source

fn downcast_err<E: Error + Send + Sync + 'static>( self, ) -> Result<Result<Arc<T>, TypedErr<E>>, QueryError>

Attempts to downcast a UserError to a specific error type.

§Returns
  • Ok(Ok(value)) - The query succeeded with value
  • Ok(Err(typed_err)) - The query failed with a UserError of type E
  • Err(query_error) - The query failed with a system error, or a UserError that is not of type E
§Example
// Handle specific error type, propagate others
let result = db.query(MyQuery::new()).downcast_err::<MyError>()?;
let value = result.map_err(|e| {
    eprintln!("MyError occurred: {}", e.message);
    e
})?;

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> QueryResultExt<T> for Result<Arc<T>, QueryError>

Source§

fn downcast_err<E: Error + Send + Sync + 'static>( self, ) -> Result<Result<Arc<T>, TypedErr<E>>, QueryError>

Implementors§