Expand description
Scan documents and images from Rust: safe, idiomatic bindings to SANE (Scanner Access Now Easy), the scanner API of Linux, the BSDs and macOS, for flatbed scanners, document feeders and multifunction printers.
use libsane::{Sane, well_known};
let sane = Sane::init()?;
for device in sane.devices(false)? {
println!("{} ({} {}, {})", device.name, device.vendor, device.model, device.kind);
}
let mut device = sane.open("test:0")?;
device.set_value(well_known::MODE, well_known::MODE_GRAY)?;
device.set_value(well_known::RESOLUTION, 150)?;
let frame = device.scan()?;
println!("{} bytes, {:?}", frame.data.len(), frame.parameters);§Overview
Saneinitializes the library (once per process at a time) and finds and opens devices. Dropping it callssane_exit.Devicereads and sets options with typed values, and starts scans.Scanreads the image data in chunks (it implementsstd::io::Read) or whole, as aFrame: raw bytes and theirParameters. With theimagefeature,Frame::to_imageconverts it to animage::DynamicImage.- Every
SANE_Statusmaps to a variant ofError.
§Blocking and threads
Every call blocks, sometimes for seconds (finding devices, warming up the
lamp, scanning). From async code, run the whole SANE session on a blocking
thread, for example with tokio::task::spawn_blocking (see Sane).
libsane is not thread-safe: a Sane can move to another thread, but
cannot be shared between threads, and its devices stay on its thread.
§System requirements
libsane and its development files, found with pkg-config, and libclang
(see the sane-sys crate). Without a scanner, SANE’s test
backend provides virtual devices: enable it in dll.conf.
§Features
image:Frame::to_image.
Re-exports§
pub use sane_sys as sys;
Modules§
- well_
known - The names of the well-known options and values of the SANE standard.
Structs§
- Capabilities
- The capabilities of an option (
SANE_CAP_*). - Credentials
- A username and password, returned by an
AuthCallback. - Device
- An open device, closed on drop (
sane_close). - Device
Info - A device found by
Sane::devices(SANE_Device). - Fixed
- A SANE fixed-point number (
SANE_Fixed): 16 integer bits, 16 fractional bits, from about -32768 to 32767.99998 in steps of 1/65536. - Frame
- A complete scanned image: the raw bytes of every line, and the parameters that describe them.
- Option
Descriptor - The description of an option of a device (
SANE_Option_Descriptor). - Parameters
- The parameters of a scan (
SANE_Parameters). - Range
- An inclusive range of values with an optional quantization step.
- Sane
- An initialized SANE library: the entry point of this crate.
- Scan
- A scan in progress, started by
Device::start. - SetInfo
- What changed after setting an option (
SANE_INFO_*). - Version
- The version of libsane (
SANE_VERSION_CODE).
Enums§
- Constraint
- The values an option accepts (
SANE_Constraint_Type). - Error
- An error returned by SANE or by this crate.
- Frame
Format - The format of a frame (
SANE_Frame). - Unit
- The physical unit of an option (
SANE_Unit). - Value
- The value of an option.
- Value
Type - The type of the value of an option (
SANE_Value_Type).
Traits§
- Option
Id - Identifies an option of a device: its index (
usize), its name (&str,String), or its descriptor.
Type Aliases§
- Auth
Callback - The function called when a backend needs credentials for a resource (for
example a password-protected network scanner): receives the resource name,
returns the credentials, or
Noneto send none. - Result
- A specialized
Resultfor SANE operations.