pub struct FactoryRegistry { /* private fields */ }Expand description
Registry for device factories.
This allows registering factories for different protocols at runtime, enabling a plugin-like architecture.
§Example
ⓘ
let mut registry = FactoryRegistry::new();
registry.register(ModbusDeviceFactory)?;
let config = DeviceConfig { /* ... */ };
let device = registry.create_device(config)?;Implementations§
Source§impl FactoryRegistry
impl FactoryRegistry
Sourcepub fn register<F: DeviceFactory + 'static>(&self, factory: F) -> Result<()>
pub fn register<F: DeviceFactory + 'static>(&self, factory: F) -> Result<()>
Register a device factory.
Sourcepub fn register_boxed(&self, factory: BoxedFactory) -> Result<()>
pub fn register_boxed(&self, factory: BoxedFactory) -> Result<()>
Register a boxed factory.
Sourcepub fn unregister(&self, protocol: Protocol) -> bool
pub fn unregister(&self, protocol: Protocol) -> bool
Unregister a factory for a protocol.
Sourcepub fn get(&self, protocol: Protocol) -> Option<Arc<BoxedFactory>>
pub fn get(&self, protocol: Protocol) -> Option<Arc<BoxedFactory>>
Get a factory for a protocol.
Sourcepub fn all_metadata(&self) -> Vec<FactoryMetadata>
pub fn all_metadata(&self) -> Vec<FactoryMetadata>
Get metadata for all registered factories.
Sourcepub fn create_device(&self, config: DeviceConfig) -> Result<BoxedDevice>
pub fn create_device(&self, config: DeviceConfig) -> Result<BoxedDevice>
Create a device using the appropriate factory.
Sourcepub fn create_devices(
&self,
configs: Vec<DeviceConfig>,
) -> Result<Vec<BoxedDevice>>
pub fn create_devices( &self, configs: Vec<DeviceConfig>, ) -> Result<Vec<BoxedDevice>>
Create multiple devices.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for FactoryRegistry
impl !RefUnwindSafe for FactoryRegistry
impl Send for FactoryRegistry
impl Sync for FactoryRegistry
impl Unpin for FactoryRegistry
impl UnsafeUnpin for FactoryRegistry
impl !UnwindSafe for FactoryRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more