Skip to main content

BackendFactory

Trait BackendFactory 

Source
pub trait BackendFactory:
    Send
    + Sync
    + Default
    + 'static {
    // Required method
    fn create(
        &self,
        config: &RingConfig,
        completion_tx: Sender<BackendCompletion>,
    ) -> Result<BoxedBackend>;

    // Provided method
    fn create_enum(
        &self,
        config: &RingConfig,
        completion_tx: Sender<BackendCompletion>,
    ) -> Result<AnyBackend> { ... }
}
Expand description

Backend construction hook used by crate::Ring.

Implementations provide a way to create backends with specific configurations. The factory pattern allows rings to be generic over backend selection while still supporting configuration-specific backend creation.

§Example

#[derive(Default)]
struct MyBackendFactory;

impl BackendFactory for MyBackendFactory {
    fn create(
        &self,
        config: &RingConfig,
        completion_tx: Sender<BackendCompletion>,
    ) -> Result<BoxedBackend> {
        Ok(Box::new(MyBackend::new(config, completion_tx)?))
    }
}

Required Methods§

Source

fn create( &self, config: &RingConfig, completion_tx: Sender<BackendCompletion>, ) -> Result<BoxedBackend>

Creates the backend for the given ring configuration (legacy API).

§Errors

Returns an error if the backend cannot be created (e.g., unsupported platform, resource exhaustion, invalid configuration).

Provided Methods§

Source

fn create_enum( &self, config: &RingConfig, completion_tx: Sender<BackendCompletion>, ) -> Result<AnyBackend>

Creates the backend as an enum-dispatched value.

The default implementation wraps the result of create into AnyBackend::Boxed. Override this in concrete factories to return specific variants for zero-cost dispatch.

§Errors

Returns an error if the backend cannot be created.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§