cpdb_rs/lib.rs
1//! Crate-level documentation for `cpdb-rs`.
2//!
3//! This library provides a native async Rust client for the
4//! [Common Print Dialog Backends (CPDB)](https://github.com/OpenPrinting/cpdb-libs)
5//! system. It communicates with CPDB backends (e.g. `cpdb-backend-cups`)
6//! over D-Bus using [`zbus`], requiring no C dependencies.
7//!
8//! # Features
9//!
10//! - `zbus-backend` *(default)* - Native async D-Bus client via [`CpdbClient`].
11//! *(Note: This uses `zbus` with the `tokio` runtime feature exclusively. Other async runtimes like `async-std` are not currently supported by the high-level client).*
12//! - `ffi` - Legacy synchronous C FFI bindings via `cpdb-libs`.
13//!
14//! # Quick start
15//!
16//! ```no_run
17//! # #[cfg(feature = "zbus-backend")]
18//! # async fn example() -> cpdb_rs::Result<()> {
19//! use cpdb_rs::CpdbClient;
20//!
21//! let client = CpdbClient::new().await?;
22//! let printers = client.get_all_printers().await?;
23//!
24//! for p in &printers {
25//! println!("{} [{}] - {}", p.name, p.id, p.make_model);
26//! }
27//!
28//! if let Some(p) = printers.first() {
29//! let (options, media) = client
30//! .get_printer_details(&p.id, &p.backend)
31//! .await?;
32//! println!("{} options, {} media sizes", options.len(), media.len());
33//! }
34//! # Ok(())
35//! # }
36//! ```
37
38#![cfg_attr(docsrs, feature(doc_cfg))]
39#![deny(missing_docs)]
40
41// cpdb-libs is a Unix/D-Bus library — there is no Windows port. Fail fast
42// with a useful message instead of letting bindgen emit a confusing linker
43// error. WSL Ubuntu is the supported path on Windows hosts; see README.
44#[cfg(all(windows, not(docsrs)))]
45compile_error!(
46 "cpdb-rs only supports Unix targets (Linux fully supported, macOS \
47 headers-only). cpdb-libs has no Windows port. If you are on Windows, \
48 develop inside WSL (Ubuntu)."
49);
50
51pub mod error;
52pub mod options;
53
54#[cfg(feature = "zbus-backend")]
55pub mod client;
56#[cfg(feature = "zbus-backend")]
57pub mod config;
58#[cfg(feature = "zbus-backend")]
59pub mod events;
60#[cfg(feature = "zbus-backend")]
61pub mod media;
62#[cfg(feature = "zbus-backend")]
63pub mod proxy;
64#[cfg(feature = "zbus-backend")]
65pub mod types;
66#[cfg(feature = "zbus-backend")]
67pub use client::CpdbClient;
68#[cfg(feature = "zbus-backend")]
69pub use config::PrinterConfig;
70#[cfg(feature = "zbus-backend")]
71pub use events::{DiscoveryEvent, PrinterSnapshot};
72#[cfg(feature = "zbus-backend")]
73pub use media::{MarginInfo, MediaCollection, MediaInfo};
74#[cfg(feature = "zbus-backend")]
75pub use types::PrinterState;
76
77// Re-export core types for convenience.
78pub use error::{CpdbError, Result};
79pub use options::{OptionInfo, OptionsCollection};
80
81#[cfg(feature = "ffi")]
82pub use cpdb_sys as ffi;
83
84#[cfg(feature = "ffi")]
85pub use cpdb_sys::callbacks::PrinterUpdate;
86#[cfg(feature = "ffi")]
87pub use cpdb_sys::{
88 common::{
89 absolute_path, concat_path, concat_sep, init, option_group, system_config_dir,
90 user_config_dir, version,
91 },
92 frontend::Frontend,
93 printer::{
94 Margin, Margins, MediaSize, PrintFdHandle, PrintSocketHandle, Printer, TranslationMap,
95 },
96 settings::{Media, Options, Settings},
97};