Skip to main content

DeviceBackend

Trait DeviceBackend 

Source
pub trait DeviceBackend: Send + Sync {
    // Required methods
    fn list<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Vec<DiscoveredDevice>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn driver_for_device(
        &self,
        device_id: &str,
        device_uri: &str,
    ) -> Option<String>;

    // Provided methods
    fn poll_status<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _config: &'life1 PrinterConfig,
    ) -> Pin<Box<dyn Future<Output = Option<PollStatus>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn identify<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _config: &'life1 PrinterConfig,
        _actions: &'life2 [String],
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

Enumerate physical printers and report their live health.

Implementations describe how to discover devices (e.g. via sysfs, BlueZ, USB enumeration) and how to map their identifying strings to a driver name registered with the framework.

driver_for_device is synchronous (pure string matching); list, poll_status, and identify are async so a backend can await its device transport (USB, Bluetooth, BLE) — e.g. a BLE LE scan or a per-device probe.

Required Methods§

Source

fn list<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Vec<DiscoveredDevice>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Discover the currently-attached devices. Returning an owned Vec (vs a borrowed callback) keeps the method cleanly async — a backend can .await a scan/probe without lifetime gymnastics around an emit closure.

Source

fn driver_for_device(&self, device_id: &str, device_uri: &str) -> Option<String>

Map a device’s IEEE 1284 device-id string and URI to a driver name that this backend recognises. Return None for “this isn’t one of mine, skip it”.

Provided Methods§

Source

fn poll_status<'life0, 'life1, 'async_trait>( &'life0 self, _config: &'life1 PrinterConfig, ) -> Pin<Box<dyn Future<Output = Option<PollStatus>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Query live status for a registered printer. The background status loop calls this on each idle printer and updates the IPP attributes when the value changes. Returning None means “no update” (keep whatever the registry already holds); returning Some carries the fresh reasons and, optionally, the loaded media and remaining-supply level.

Source

fn identify<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _config: &'life1 PrinterConfig, _actions: &'life2 [String], ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Handle an Identify-Printer request (PWG 5100.14 §5.1) — make the physical device announce itself (beep, flash an LED, …). actions holds the requested identify-actions keywords (display, sound, flash, speak); an empty slice means “use the default action”. Default: no-op.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§