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
impl BackendRegistry
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new backend registry.
§Examples
use canlink_hal::BackendRegistry;
let registry = BackendRegistry::new();Sourcepub fn global() -> Arc<Self>
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();Sourcepub fn register(&self, factory: Arc<dyn BackendFactory>) -> CanResult<()>
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()))?;Sourcepub fn unregister(&self, name: &str) -> CanResult<()>
pub fn unregister(&self, name: &str) -> CanResult<()>
Sourcepub fn create(
&self,
name: &str,
config: &BackendConfig,
) -> CanResult<Box<dyn CanBackend>>
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 nameconfig- Backend configuration
§Returns
A boxed backend instance ready for initialization.
§Errors
CanError::BackendNotFound- Backend not registeredCanError::ConfigError- Invalid configuration
§Thread Safety
This method is thread-safe and can be called from multiple threads.
§Examples
let backend = registry.create("mock", &config)?;Sourcepub fn list_backends(&self) -> Vec<String>
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);
}Sourcepub fn get_backend_info(&self, name: &str) -> CanResult<BackendInfo>
pub fn get_backend_info(&self, name: &str) -> CanResult<BackendInfo>
Sourcepub fn is_registered(&self, name: &str) -> bool
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");
}