Skip to main content

BackendRegistry

Struct BackendRegistry 

Source
pub struct BackendRegistry { /* private fields */ }
Expand description

Backend registry.

Manages all registered hardware backends and provides methods for registration, querying, and creating backend instances.

§Thread Safety

All methods of BackendRegistry are thread-safe and can be called from multiple threads simultaneously. Internal state is protected by RwLock.

§Examples

use canlink_hal::BackendRegistry;

// Register a backend
let registry = BackendRegistry::new();
registry.register(Box::new(MockBackendFactory::new()))?;

// Query available backends
let backends = registry.list_backends();
println!("Available backends: {:?}", backends);

// Create a backend instance
let backend = registry.create("mock", &config)?;

Implementations§

Source§

impl BackendRegistry

Source

pub fn new() -> Self

Create a new backend registry.

§Examples
use canlink_hal::BackendRegistry;

let registry = BackendRegistry::new();
Source

pub fn global() -> Arc<Self>

Get the global registry instance (singleton).

This returns a shared reference to the global registry. The global registry is initialized on first access and persists for the lifetime of the program.

§Examples
use canlink_hal::BackendRegistry;

let registry = BackendRegistry::global();
Source

pub fn register(&self, factory: Arc<dyn BackendFactory>) -> CanResult<()>

Register a backend factory.

Registers a new backend factory with the registry. The backend name must be unique.

§Arguments
  • factory - Backend factory instance
§Errors
  • CanError::BackendAlreadyRegistered - Backend name already registered
§Thread Safety

This method is thread-safe and can be called from multiple threads.

§Examples
registry.register(Box::new(MockBackendFactory::new()))?;
Source

pub fn unregister(&self, name: &str) -> CanResult<()>

Unregister a backend.

Removes a backend factory from the registry.

§Arguments
  • name - Backend name
§Errors
  • CanError::BackendNotFound - Backend not registered
§Examples
registry.unregister("mock")?;
Source

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

Create a backend instance.

Creates a new backend instance using the registered factory.

§Arguments
  • name - Backend name
  • config - Backend configuration
§Returns

A boxed backend instance ready for initialization.

§Errors
  • CanError::BackendNotFound - Backend not registered
  • CanError::ConfigError - Invalid configuration
§Thread Safety

This method is thread-safe and can be called from multiple threads.

§Examples
let backend = registry.create("mock", &config)?;
Source

pub fn list_backends(&self) -> Vec<String>

List all registered backends.

Returns a list of all backend names currently registered, in registration order. Backends are returned in the order they were registered, with earlier registrations appearing first in the list.

§Panics

Panics if the internal lock is poisoned (should never happen in normal operation).

§Examples
let backends = registry.list_backends();
for name in backends {
    println!("Available: {}", name);
}
Source

pub fn get_backend_info(&self, name: &str) -> CanResult<BackendInfo>

Get backend information.

Returns metadata about a registered backend.

§Arguments
  • name - Backend name
§Errors
  • CanError::BackendNotFound - Backend not registered
§Examples
let info = registry.get_backend_info("mock")?;
println!("Backend: {} v{}", info.name, info.version);
Source

pub fn is_registered(&self, name: &str) -> bool

Check if a backend is registered.

§Arguments
  • name - Backend name
§Returns

true if the backend is registered, false otherwise.

§Panics

Panics if the internal lock is poisoned (should never happen in normal operation).

§Examples
if registry.is_registered("mock") {
    println!("Mock backend is available");
}

Trait Implementations§

Source§

impl Default for BackendRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.