Crate cups_rs

Crate cups_rs 

Source
Expand description

§cups-rs: Safe Rust Bindings for CUPS (Common UNIX Printing System)

cups-rs provides a safe, idiomatic Rust interface to the CUPS printing system API. It wraps the C CUPS library with memory-safe abstractions while maintaining high performance.

§Features

  • Printer Discovery: Enumerate and discover available printers on the network
  • Job Management: Create, submit, monitor, and cancel print jobs
  • Authentication: Support for password callbacks and certificate-based authentication
  • Multi-document Jobs: Submit multiple documents as a single print job
  • Advanced Queries: Query printer capabilities, supported media, and options
  • IPP Protocol: Low-level IPP request/response handling for custom workflows
  • Server Configuration: Manage CUPS server settings, encryption, and user preferences
  • Localization: Get localized printer option names and values

§Quick Start

§Discovering Printers

use cups_rs::get_all_destinations;

let printers = get_all_destinations().expect("Failed to get printers");
for printer in printers {
    println!("Printer: {} ({})", printer.name,
             if printer.is_default { "default" } else { "available" });
}

§Printing a Document

use cups_rs::{get_default_destination, create_job};

let printer = get_default_destination().expect("No default printer");
let job = create_job(&printer, "My Document")
    .expect("Failed to create job");

job.submit_file("document.pdf", "application/pdf")
    .expect("Failed to submit document");

§Advanced Job Options

use cups_rs::{get_destination, create_job_with_options, PrintOptions, ColorMode, DuplexMode, Orientation};

let printer = get_destination("MyPrinter").expect("Printer not found");

let options = PrintOptions::default()
    .copies(3)
    .color_mode(ColorMode::Color)
    .duplex(DuplexMode::TwoSidedPortrait)
    .orientation(Orientation::Landscape);

let job = create_job_with_options(&printer, "Report", &options)
    .expect("Failed to create job");

§Module Overview

  • auth: Authentication and security layer (password callbacks, certificates)
  • config: CUPS server configuration (server, user, encryption settings)
  • connection: Direct HTTP connections to printers and CUPS servers
  • destination: Printer discovery and destination management
  • ipp: Low-level IPP (Internet Printing Protocol) request/response handling
  • job: Print job creation, submission, and management
  • options: Print option parsing, encoding, and manipulation
  • Error and Result: Error types and result handling

§API Coverage

This library currently implements approximately 70% of the CUPS C API, focusing on:

  • Core printing workflows
  • Enterprise features (authentication, multi-server support)
  • Advanced destination and job management
  • Low-level IPP protocol access

§Safety

All unsafe FFI calls to the CUPS C library are wrapped in safe Rust abstractions. Memory management is handled automatically using RAII patterns with Drop implementations.

§Platform Support

  • Linux (tested)
  • macOS (should work, uses system CUPS)
  • Other UNIX-like systems with CUPS installed

§Requirements

  • CUPS development libraries (libcups2-dev on Debian/Ubuntu, cups-devel on Fedora)
  • Rust 1.70 or later

Re-exports§

pub use connection::ConnectionFlags;
pub use connection::HttpConnection;
pub use connection::connect_to_destination;
pub use destination::Destination;
pub use destination::DestinationInfo;
pub use destination::Destinations;
pub use destination::MediaSize;
pub use destination::PrinterState;
pub use destination::OptionConflict;
pub use destination::copy_dest;
pub use destination::enum_destinations;
pub use destination::find_destinations;
pub use destination::get_all_destinations;
pub use destination::get_default_destination;
pub use destination::get_destination;
pub use destination::remove_dest;
pub use job::ColorMode;
pub use job::DuplexMode;
pub use job::JobInfo;
pub use job::JobStatus;
pub use job::Orientation;
pub use job::PrintOptions;
pub use job::PrintQuality;
pub use job::create_job;
pub use job::create_job_with_options;
pub use job::get_active_jobs;
pub use job::get_completed_jobs;
pub use ipp::IppAttribute;
pub use ipp::IppOperation;
pub use ipp::IppRequest;
pub use ipp::IppResponse;
pub use ipp::IppStatus;
pub use ipp::IppTag;
pub use ipp::IppValueTag;
pub use options::add_integer_option;
pub use options::add_option;
pub use options::encode_option;
pub use options::encode_options;
pub use options::encode_options_with_group;
pub use options::get_integer_option;
pub use options::get_option;
pub use options::parse_options;
pub use options::remove_option;
pub use constants::*;

Modules§

auth
Authentication and security layer for CUPS
bindings
Raw FFI bindings to the CUPS C library
config
CUPS server configuration management
connection
Direct HTTP connection management for printers and CUPS servers
constants
CUPS constants and enums Constants for CUPS options and values
destination
Printer discovery and destination management
ipp
Low-level IPP (Internet Printing Protocol) request/response handling
job
Print job creation, submission, and management
options
Print option parsing, encoding, and manipulation

Enums§

Error
ErrorCategory

Type Aliases§

Result