lamco_clipboard_core/
lib.rs

1//! # lamco-clipboard-core
2//!
3//! Protocol-agnostic clipboard utilities for Rust.
4//!
5//! This crate provides core clipboard functionality that can be used with any
6//! clipboard backend (Portal, X11, headless, etc.):
7//!
8//! - **[`ClipboardSink`] trait** - Abstract clipboard backend interface
9//! - **[`FormatConverter`]** - MIME ↔ Windows clipboard format conversion
10//! - **[`LoopDetector`]** - Prevent clipboard sync loops with content hashing
11//! - **[`TransferEngine`]** - Chunked transfer for large clipboard data
12//!
13//! ## Quick Start
14//!
15//! ```rust
16//! use lamco_clipboard_core::{ClipboardSink, FormatConverter, LoopDetector};
17//! use lamco_clipboard_core::formats::{ClipboardFormat, mime_to_rdp_formats};
18//!
19//! // Convert MIME types to RDP formats
20//! let formats = mime_to_rdp_formats(&["text/plain", "text/html"]);
21//!
22//! // Check for clipboard loops
23//! let mut detector = LoopDetector::new();
24//! if !detector.would_cause_loop(&formats) {
25//!     // Safe to sync
26//! }
27//! ```
28//!
29//! ## Feature Flags
30//!
31//! - `image` - Enable image format conversion (PNG, JPEG, BMP ↔ DIB)
32//!
33//! ## Architecture
34//!
35//! The [`ClipboardSink`] trait provides an async interface for clipboard operations.
36//! Implementations handle the actual clipboard access (Portal D-Bus, X11, etc.)
37//! while this crate handles format conversion and loop detection.
38
39#![cfg_attr(docsrs, feature(doc_cfg))]
40#![deny(missing_docs)]
41
42mod error;
43mod sink;
44mod transfer;
45
46pub mod formats;
47pub mod loop_detector;
48pub mod sanitize;
49
50#[cfg(feature = "image")]
51pub mod image;
52
53pub use error::{ClipboardError, ClipboardResult};
54pub use formats::{
55    build_file_group_descriptor_w, ClipboardFormat, FileDescriptor, FileDescriptorFlags, FormatConverter,
56};
57pub use loop_detector::{ClipboardSource, LoopDetectionConfig, LoopDetector};
58pub use sink::{ClipboardChange, ClipboardChangeReceiver, ClipboardChangeReceiverInner, ClipboardSink, FileInfo};
59pub use transfer::{
60    TransferConfig, TransferEngine, TransferProgress, TransferState, DEFAULT_CHUNK_SIZE, DEFAULT_MAX_SIZE,
61    DEFAULT_TIMEOUT_MS,
62};
63
64/// Prelude module for convenient imports
65pub mod prelude {
66    pub use crate::formats::{mime_to_rdp_formats, rdp_format_to_mime};
67    pub use crate::{ClipboardChange, ClipboardError, ClipboardResult, ClipboardSink, FormatConverter, LoopDetector};
68}