Skip to main content

RasterDriver

Trait RasterDriver 

Source
pub trait RasterDriver:
    Sized
    + Send
    + 'static {
    type Device: Send + Sync;

    // Required methods
    fn start_job(
        printer: &PrinterHandle<'_>,
        options: &JobOptions,
        device: &Self::Device,
    ) -> Result<Self, JobFailure>;
    fn write_line(
        &mut self,
        options: &JobOptions,
        y: u32,
        line: &[u8],
    ) -> Result<(), JobFailure>;
    fn end_page<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 mut self,
        options: &'life1 JobOptions,
        page: u32,
        device: &'life2 Self::Device,
    ) -> Pin<Box<dyn Future<Output = Result<(), JobFailure>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn end_job<'life0, 'async_trait>(
        self,
        device: &'life0 Self::Device,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn start_page(
        &mut self,
        _options: &JobOptions,
        _page: u32,
        _device: &Self::Device,
    ) -> Result<(), JobFailure> { ... }
}
Expand description

Driver that turns a stream of raster scanlines into device bytes.

Implementations are per-job statefulstart_job returns a fresh value that owns the page buffer, write_line accumulates scanlines, end_page transfers the page to the device, end_job releases resources. The framework’s IPP Print-Job handler drives this trait; you only need to provide a type that knows how to talk to your device.

start_job/start_page/write_line are synchronous (they only build and fill the page buffer); the device-touching end_page/end_job are async so the driver can await a transport (USB HID, Bluetooth RFCOMM, BLE GATT) without blocking the runtime.

Required Associated Types§

Source

type Device: Send + Sync

The driver’s opaque device handle (e.g. an open HID descriptor).

Required Methods§

Source

fn start_job( printer: &PrinterHandle<'_>, options: &JobOptions, device: &Self::Device, ) -> Result<Self, JobFailure>

Allocate per-job state. Called once at the top of each job.

Source

fn write_line( &mut self, options: &JobOptions, y: u32, line: &[u8], ) -> Result<(), JobFailure>

Append one scanline to the page buffer.

Source

fn end_page<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, options: &'life1 JobOptions, page: u32, device: &'life2 Self::Device, ) -> Pin<Box<dyn Future<Output = Result<(), JobFailure>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Transfer the completed page to the device (and repeat for copies).

Source

fn end_job<'life0, 'async_trait>( self, device: &'life0 Self::Device, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Release per-job state. Called once at the end of the job.

Provided Methods§

Source

fn start_page( &mut self, _options: &JobOptions, _page: u32, _device: &Self::Device, ) -> Result<(), JobFailure>

Called once per page before any write_line. Default: no-op.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§