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 new() -> FactoryRegistry
pub fn new() -> FactoryRegistry
Create a new empty registry.
Sourcepub fn register<F>(&self, factory: F) -> Result<(), Error>where
F: DeviceFactory + 'static,
pub fn register<F>(&self, factory: F) -> Result<(), Error>where
F: DeviceFactory + 'static,
Register a device factory.
Sourcepub fn register_boxed(
&self,
factory: Box<dyn DeviceFactory>,
) -> Result<(), Error>
pub fn register_boxed( &self, factory: Box<dyn DeviceFactory>, ) -> Result<(), Error>
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<Box<dyn DeviceFactory>>>
pub fn get(&self, protocol: Protocol) -> Option<Arc<Box<dyn DeviceFactory>>>
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<Box<dyn Device>, Error>
pub fn create_device( &self, config: DeviceConfig, ) -> Result<Box<dyn Device>, Error>
Create a device using the appropriate factory.
Sourcepub fn create_devices(
&self,
configs: Vec<DeviceConfig>,
) -> Result<Vec<Box<dyn Device>>, Error>
pub fn create_devices( &self, configs: Vec<DeviceConfig>, ) -> Result<Vec<Box<dyn Device>>, Error>
Create multiple devices.
Trait Implementations§
Source§impl Default for FactoryRegistry
impl Default for FactoryRegistry
Source§fn default() -> FactoryRegistry
fn default() -> FactoryRegistry
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !Freeze for FactoryRegistry
impl !RefUnwindSafe for FactoryRegistry
impl Send for FactoryRegistry
impl Sync for FactoryRegistry
impl Unpin 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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more