Skip to main content

delegate_expose

Macro delegate_expose 

Source
macro_rules! delegate_expose {
    (
        impl<$($lt:lifetime),* $(,)? $($generic:ident),+> for $wrapper:ty
        where { $($bound:tt)+ }
        => $field:ident
    ) => { ... };
    (
        impl<$($lt:lifetime),* $(,)? $($generic:ident),+> for $wrapper:ty
        where { $($bound:tt)+ }
        => $field:ident,
        wrap = |$this:ident, $result:ident| $wrap_body:expr
    ) => { ... };
}
Expand description

Delegates FetchById, Update, Reschedule, Vacuum, ResumeById, ResumeAbandoned, RegisterWorker, and WaitForCompletion to a named field in one call. The caller supplies shared extra bounds, and optionally a wrap expression applied to every delegated method’s Result.

wrap receives the Result<T, B::Error> returned by the inner call and must produce the wrapper’s own Result<T, Self::Error> — use it for .map_err(...), logging, retries, or any other postprocessing.

The impl<...> generic list may include a leading lifetime (e.g. impl<'a, B>) when the wrapper type itself is generic over a lifetime.

ⓘ
// plain forwarding
delegate_expose!(
    impl<B> for RawDataBackend<B>
    where {
        B: Send + 'static,
        B::Compact: Send + Clone + 'static,
    }
    => inner
);

// with a lifetime parameter
delegate_expose!(
    impl<'a, B> for BorrowedBackend<'a, B>
    where {
        B: Send + 'static,
    }
    => inner
);

// with postprocessing
delegate_expose!(
    impl<B, F, E2> for MapErr<B, F>
    where {
        B: Backend,
        F: Fn(B::Error) -> E2,
        E2: std::error::Error + Send + Sync + 'static,
    }
    => backend,
    wrap = |this, result| result.map_err(|err| (this.f)(err))
);