Trait StatementCallbackReturnType

Source
pub trait StatementCallbackReturnType<S: 'static, C> {
    type Return<'a>;

    // Required methods
    fn from_error<'a>(e: Error) -> Self::Return<'a>;
    fn map_to_no_cache<'a>(self) -> Self::Return<'a>
       where Self: 'a;
    fn map_to_cache(stmt: &mut S, conn: C) -> Self::Return<'_>;
    fn register_cache<'a>(
        self,
        callback: impl FnOnce(S) -> &'a mut S + Send + 'a,
    ) -> Self::Return<'a>
       where Self: 'a;
}
Available on crate feature i-implement-a-third-party-backend-and-opt-into-breaking-changes only.
Expand description

This trait abstracts over the type returned by the prepare statement function

The main use-case for this abstraction is to share the same statement cache implementation between diesel and diesel-async.

Required Associated Types§

Source

type Return<'a>

The return type of StatementCache::cached_statement

Either a QueryResult<MaybeCached<S>> or a future of that result type

Required Methods§

Source

fn from_error<'a>(e: Error) -> Self::Return<'a>

Create the return type from an error

Source

fn map_to_no_cache<'a>(self) -> Self::Return<'a>
where Self: 'a,

Map the callback return type to the MaybeCached::CannotCache variant

Source

fn map_to_cache(stmt: &mut S, conn: C) -> Self::Return<'_>

Map the cached statement to the MaybeCached::Cached variant

Source

fn register_cache<'a>( self, callback: impl FnOnce(S) -> &'a mut S + Send + 'a, ) -> Self::Return<'a>
where Self: 'a,

Insert the created statement into the cache via the provided callback and then turn the returned reference into MaybeCached::Cached

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<S, C> StatementCallbackReturnType<S, C> for QueryResult<S>
where S: 'static,