Skip to main content

Crate day_part_clipboard

Crate day_part_clipboard 

Source
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 None when 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, Win32 IsClipboardFormatAvailable, …); otherwise it reads the text.
set_text
Place text on the system clipboard as plain text, replacing the previous contents. Returns true on success, false when the platform has no clipboard API or the write failed (e.g. no wl-copy/xclip binary on Linux).
Day API ↩ Guides· daybrite.dev