Skip to main content

BackendFactory

Trait BackendFactory 

Source
pub trait BackendFactory: Send + Sync {
    // Required methods
    fn create(&self, config: &BackendConfig) -> CanResult<Box<dyn CanBackend>>;
    fn name(&self) -> &str;
    fn version(&self) -> BackendVersion;
}
Expand description

Backend factory trait.

This trait defines the factory pattern for creating backend instances. Each backend implementation should provide a factory that implements this trait.

§Examples

use canlink_hal::{BackendFactory, BackendConfig};

struct MockBackendFactory;

impl BackendFactory for MockBackendFactory {
    fn create(&self, config: &BackendConfig) -> CanResult<Box<dyn CanBackend>> {
        Ok(Box::new(MockBackend::new()))
    }

    fn name(&self) -> &str {
        "mock"
    }

    fn version(&self) -> BackendVersion {
        BackendVersion::new(0, 1, 0)
    }
}

Required Methods§

Source

fn create(&self, config: &BackendConfig) -> CanResult<Box<dyn CanBackend>>

Create a new backend instance.

§Arguments
  • config - Backend configuration
§Returns

A boxed backend instance ready for initialization.

§Errors
  • CanError::ConfigError - Invalid configuration
  • CanError::Other - Factory-specific errors
Source

fn name(&self) -> &str

Get the factory name.

Returns the unique identifier for this backend type.

Source

fn version(&self) -> BackendVersion

Get the factory version.

Returns the version of the backend implementation.

Implementors§