depot/rust/passgen/src/scanner.rs

18 lines
529 B
Rust

use std::path::PathBuf;
use anyhow::{anyhow, Result};
pub fn scan(image_path: &PathBuf) -> Result<String> {
let image_path_str = (*image_path)
.to_str()
.ok_or_else(|| anyhow!("invalid path"))?;
rxing::helpers::detect_in_file(image_path_str, Some(rxing::BarcodeFormat::AZTEC))
.map_err(|e| {
anyhow!(
"could not parse Aztec barcode from image {}: {}",
image_path_str,
e
)
})
.map(|r| r.getText().clone())
}