code-scanner-driver 0.1.0

Driver for barcode scanners and keyboard input with GTIN validation, async streaming, and burst detection.
Documentation

code-scanner-driver

Crates.io Docs.rs

A lightweight Rust driver for barcode scanners and keyboard-emulated input, featuring:

  • GTIN validation (GTIN-8/12/13/14)
  • Async streaming using Tokio
  • Burst detection for grouping fast keystrokes into scan events
  • Cross-platform global keyboard listener via rdev
  • Supports all USB/HID scanners that behave like a keyboard

Features

  • Scanner input detection
    Groups rapid keystrokes into a single scan event.

  • GTIN validation
    Checks GTIN-8 / GTIN-12 / GTIN-13 / GTIN-14 via checksum.

  • Async stream API
    Uses tokio_stream for ergonomic event consumption.

  • Global keyboard hook
    Powered by rdev, works across platforms.


Installation

Add to your Cargo.toml:

[dependencies]

code-scanner-driver = "0.1"


Quick Start

use code_scanner_driver::ScannerStream;
use tokio_stream::StreamExt;

#[tokio::main]
async fn main() {
  let mut stream = ScannerStream::new().unwrap();
  println!("Listening for scans...");

  while let Some(event) = stream.next().await {
    println!("Scan received: {:?}", event);
  }
}

GTIN Validation Example

use code_scanner_driver::validate_gtin;

let code = "5901234123457";

match validate_gtin(code) {
  Some(kind) => println!("{} is a valid {}", code, kind),
  None => println!("{} is NOT a valid GTIN", code),
}

Supported formats:

  • GTIN-8
  • GTIN-12
  • GTIN-13
  • GTIN-14