copypasta
A cross-platform Rust library for getting and setting the contents of the OS-level system clipboard.
Repository Health
Technical Analysis
copypasta is a cross-platform Rust library for reading from and writing to the operating system clipboard. Originally a fork of rust-clipboard maintained by the Alacritty terminal project, it adds first-class Wayland clipboard support alongside the existing Windows, macOS, and X11 backends.
The library exposes a single ClipboardProvider trait with get_contents and set_contents methods, and a ClipboardContext type alias that resolves to the correct platform backend via conditional compilation. This lets applications interact with the clipboard through one consistent API regardless of the target OS or display server.
What You Get
- A unified ClipboardProvider trait with get_contents and set_contents
- Backends for Windows, macOS, X11, and Wayland selected via conditional compilation
- First-class Wayland clipboard support added on top of the original rust-clipboard fork
- A NopClipboardContext fallback for headless or unsupported environments
- Feature flags to opt into or out of X11 and Wayland dependencies
Common Use Cases
- Adding copy and paste support to a terminal emulator or GUI application
- Reading clipboard contents to feed into a command-line tool
- Writing generated text or results back to the system clipboard
Under The Hood
Architecture - The crate centers on the ClipboardProvider trait defined in common.rs, with one implementation per platform in windows_clipboard.rs, osx_clipboard.rs, x11_clipboard.rs, wayland_clipboard.rs, and a nop_clipboard.rs fallback. lib.rs uses cfg conditional compilation to alias ClipboardContext to whichever backend matches the target OS and display server.
Tech Stack - Written in Rust (edition 2021, MSRV 1.71). Platform backends pull in targeted dependencies only where needed: clipboard-win on Windows, objc2/objc2-foundation/objc2-app-kit on macOS, and x11-clipboard plus smithay-clipboard on Unix, with X11 and Wayland gated behind Cargo feature flags (including a wayland-dlopen option).
Code Quality - The codebase is small and cleanly partitioned by platform, following the conditional-compilation pattern idiomatic to cross-platform Rust crates. It is maintained under the Alacritty organization, which gives it real-world usage as the clipboard layer of a widely used terminal. Automated test coverage is minimal, as clipboard behavior is inherently tied to a live windowing environment; correctness is instead validated through downstream use.
API Design - The public API is intentionally tiny: two methods on one trait plus a platform-resolved type alias, with runnable examples (hello_world.rs, primary_selection.rs) showing typical usage. This keeps the learning curve very low while the compile-time backend selection hides all platform complexity from callers.