rust-clipboard is a cross-platform library for getting and setting the contents of the OS-level clipboard.
It has been tested on Windows, Mac OSX, GNU/Linux, and FreeBSD.
It is used in Mozilla Servo.
On Linux you need the x11 library, install it with something like:
sudo apt-get install xorg-dev
extern crate clipboard;
use clipboard::ClipboardContext;
fn example() {
let mut ctx = ClipboardContext::new().unwrap();
println!("{:?}", ctx.get_contents());
ctx.set_contents("some string".to_owned()).unwrap();
}
The ClipboardProvider
trait has the following functions:
fn get_contents(&mut self) -> Result<String, Box<Error>>;
fn set_contents(&mut self, String) -> Result<(), Box<Error>>;
ClipboardContext
is a type alias for one of {WindowsClipboardContext
, OSXClipboardContext
, X11ClipboardContext
, NopClipboardContext
}, all of which implement ClipboardProvider
. Which concrete type is chosen for ClipboardContext
depends on the OS (via conditional compilation).
rust-clipboard
is dual-licensed under MIT and Apache2.