Skip to main content

DevicePlugin

Trait DevicePlugin 

Source
pub trait DevicePlugin:
    Send
    + Sync
    + 'static {
    // Required methods
    fn kind(&self) -> &'static str;
    fn config_schema(&self) -> Schema;
    fn faults(&self) -> Vec<FaultId>;
    fn create(
        &self,
        id: DeviceId,
        config: Value,
    ) -> Result<Box<dyn Device>, ConfigError>;
}
Expand description

A device type that can be instantiated from JSON config, e.g. printer-escpos.

Register plugins with Registry::register.

Required Methods§

Source

fn kind(&self) -> &'static str

The device kind this plugin creates, e.g. "printer-escpos".

Source

fn config_schema(&self) -> Schema

JSON Schema for the config accepted by DevicePlugin::create.

Source

fn faults(&self) -> Vec<FaultId>

Every fault a device of this kind can support, e.g. for listing faults by kind. A particular instance may support fewer, see Device::faults.

Source

fn create( &self, id: DeviceId, config: Value, ) -> Result<Box<dyn Device>, ConfigError>

Creates a device instance. Invalid config is a ConfigError, never a panic.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§