Answer#
arboard is a clipboard crate for Windows, macOS and Linux. You make a Clipboard, then call set_text to copy and get_text to paste.
[dependencies]
arboard = "3"use arboard::Clipboard;
fn main() -> Result<(), arboard::Error> {
let mut clipboard = Clipboard::new()?; // keep this value alive while the app runs
clipboard.set_text("copied from Rust")?;
let text = clipboard.get_text()?;
println!("clipboard now holds: {text}");
Ok(())
}This compiled (cargo check) with arboard 3.7.0 on Windows 11. It was not executed for this thread, so there is no output to show: running it replaces whatever the person had copied.
Points to design for:
- Everything returns
Result. The clipboard can be locked by another program, hold something that is not text, or be unavailable.get_texton a clipboard that holds an image returns an error; show a message or ignore it, but do notunwrap. - Keep one
Clipboard. Make it once and store it in your app state rather than creating one per call. The arboard documentation has notes on platforms where the clipboard's content is tied to the program that owns it; read them if you target Linux. - Let the toolkit do it when it can. Text boxes in egui, iced and Slint already handle Ctrl+C and Ctrl+V (Cmd on macOS). Use arboard for your own "Copy path" or "Copy result" buttons, or when the toolkit has no clipboard access.
- Do not paste blindly. Pasted text is untrusted input: check its length and content as you would for a file.
Common mistakes#
- Dropping the
Clipboardimmediately afterset_texton Linux, which can lose the text. Keep the value alive. - Putting a secret on the clipboard and leaving it there. Other programs can read the clipboard.
Related questions#
Can I copy an image?#
arboard has set_image and get_image with an image data structure; check the crate documentation for the format it expects (RGBA bytes with width and height).
Sources#
- arboard repository: https://github.com/1Password/arboard (read 2026-12-05)
- arboard documentation: https://docs.rs/arboard/3.7.0/arboard/ (read 2026-12-05)