A clipboard for Rust
Find a file
2017-09-05 19:49:06 +01:00
examples Correct conditional compilation. 2017-09-05 19:49:06 +01:00
src Add support for x11 primary selection. 2017-09-05 19:31:44 +01:00
.gitignore Upgrade to rustc 1.0.0-dev (47551b574 2015-04-14) (built 2015-03-18) 2015-04-23 18:09:02 +02:00
.travis.yml Fix syntax in osx_clipboard.rs. Change comment position in .travis.yml (for some reason the apt-get line tried to run on Travis OSX, even though it's commented). 2017-03-08 19:51:10 -05:00
appveyor.yml Enable CI via Travis and Appveyor. 2017-03-08 16:05:10 -05:00
Cargo.toml Upgrade x11-clipboard to v0.2 2017-08-30 19:12:24 -05:00
LICENSE.apache2 Add license headers. Update cargo metadata. 2016-03-14 13:04:44 -04:00
LICENSE.mit Add dual-license as per issue #41. Bump version to 0.4.0. 2017-06-19 15:50:47 -04:00
README.md Add dual-license as per issue #41. Bump version to 0.4.0. 2017-06-19 15:50:47 -04:00

rust-clipboard

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, and GNU/Linux.
It is used in Mozilla Servo.

Appveyor Build Status Travis Build Status

Prerequisites

On Linux you need the x11 library, install it with something like:

sudo apt-get install xorg-dev

Example

extern crate clipboard;

use clipboard::ClipboardProvider;
use clipboard::ClipboardContext;

fn example() {
    let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap();
    println!("{}", ctx.get_contents());
    ctx.set_contents("some string".to_owned());
}

API

The ClipboardProvider trait has the following functions:

fn new() -> Result<Self, Box<Error>>;
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).

License

rust-clipboard is dual-licensed under MIT and Apache2.