apalis_core/backend/
shared.rs

1//! # Shared connection support for backends
2//!
3//! The [`MakeShared`] trait defines how to create shared backend instances, potentially with configuration options.
4//! This allows for flexible and reusable backend implementations that can be easily integrated into different parts of an application.
5//!
6//! ## Features:
7//! - `MakeShared` trait: Defines methods for creating shared backend instances, with or without configuration.
8//! - Support for various backend types, enabling code reuse and consistency across workers.
9//! - Performance optimizations by allowing backends to reuse connections and resources.
10
11/// Trait for creating shared backend instances
12pub trait MakeShared<Args> {
13    /// The backend type to be shared
14    type Backend;
15    /// The Config for the backend
16    type Config;
17    /// The error returned if the backend cant be shared
18    type MakeError;
19
20    /// Returns the backend to be shared
21    fn make_shared(&mut self) -> Result<Self::Backend, Self::MakeError>
22    where
23        Self::Config: Default,
24    {
25        self.make_shared_with_config(Default::default())
26    }
27
28    /// Returns the backend with config
29    fn make_shared_with_config(
30        &mut self,
31        config: Self::Config,
32    ) -> Result<Self::Backend, Self::MakeError>;
33}