Expand description
day-part-clipboard — a HEADLESS cross-platform plain-text clipboard API. No UI; any Rust code can
depend on this crate and call set_text / get_text / has_text to reach the system
clipboard through the platform’s NATIVE API.
day_part_clipboard::set_text("hello");
if let Some(text) = day_part_clipboard::get_text() {
println!("clipboard holds: {text}");
}Platform selection is purely #[cfg(target_os)]/#[cfg(target_env)] (the clipboard is an OS
concern, not a widget-toolkit one): macOS uses NSPasteboard (toolkit-independent — it works
under day-qt binaries too), iOS UIPasteboard, Windows the Win32 clipboard (CF_UNICODETEXT),
desktop Linux shells out to wl-copy/wl-paste (Wayland) with an xclip (X11) fallback,
HarmonyOS the native Pasteboard/UDMF C API, and Android ClipboardManager (via a Java shim
staged by day build). Platforms without a clipboard API return false/None.
Platform caveats: Android 10+ only lets the app read the clipboard while it has input focus —
get_text returns None in the background. Desktop Linux requires wl-clipboard or xclip
to be installed (both are ubiquitous distro packages).
Functions§
- get_
text - Read the current clipboard contents as plain text. Returns
Nonewhen the clipboard is empty, holds no text representation, or the platform denies access (e.g. an unfocused Android app). - has_
text - Whether the clipboard currently holds text. Cheap where the platform offers a dedicated check
(
UIPasteboard.hasStrings, Win32IsClipboardFormatAvailable, …); otherwise it reads the text. - set_
text - Place
texton the system clipboard as plain text, replacing the previous contents. Returnstrueon success,falsewhen the platform has no clipboard API or the write failed (e.g. nowl-copy/xclipbinary on Linux).