Skip to main content

QueryOutput

Trait QueryOutput 

Source
pub trait QueryOutput:
    PartialEq
    + Send
    + Sync
    + 'static { }
Expand description

Convenience trait for query output types.

This trait combines the bounds needed for a type to be used as a query output: PartialEq + Send + Sync + 'static.

  • PartialEq is required for the default output_eq comparison (early cutoff optimization)
  • Send + Sync + 'static allows the output to be cached and shared across threads

§When to Use

Use QueryOutput for generic type parameters that appear only in query output:

#[query]
fn parse<T: QueryOutput + FromStr>(db: &impl Db, text: String) -> Result<T, QueryError>
where
    T::Err: Display,
{
    text.parse().map_err(|e| anyhow!("{}", e).into())
}

§When Not to Use

If you’re using #[query(output_eq = none)] or a custom output_eq function, you don’t need PartialEq. In that case, use raw bounds instead:

#[query(output_eq = none)]
fn create<T: Send + Sync + 'static>(db: &impl Db) -> Result<T, QueryError> { ... }

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.

Implementors§

Source§

impl<T: PartialEq + Send + Sync + 'static> QueryOutput for T