README.md
1# rust-clipboard
2
3rust-clipboard is a cross-platform library for getting and setting the contents of the OS-level clipboard.
4It has been tested on Windows, Mac OSX, GNU/Linux, and FreeBSD.
5It is used in Mozilla Servo.
6
7[![](http://meritbadge.herokuapp.com/clipboard)](https://crates.io/crates/clipboard)
8[![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/github/aweinstock314/rust-clipboard)](https://ci.appveyor.com/project/aweinstock314/rust-clipboard)
9[![Travis Build Status](https://travis-ci.org/aweinstock314/rust-clipboard.svg?branch=master)](https://travis-ci.org/aweinstock314/rust-clipboard)
10
11## Prerequisites
12
13On Linux you need the x11 library, install it with something like:
14
15```bash
16sudo apt-get install xorg-dev
17```
18
19## Example
20
21```rust
22extern crate clipboard;
23
24use clipboard::ClipboardProvider;
25use clipboard::ClipboardContext;
26
27fn example() {
28 let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap();
29 println!("{:?}", ctx.get_contents());
30 ctx.set_contents("some string".to_owned()).unwrap();
31}
32```
33
34## API
35
36The `ClipboardProvider` trait has the following functions:
37
38```rust
39fn new() -> Result<Self, Box<Error>>;
40fn get_contents(&mut self) -> Result<String, Box<Error>>;
41fn set_contents(&mut self, String) -> Result<(), Box<Error>>;
42```
43
44`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).
45
46## License
47
48`rust-clipboard` is dual-licensed under MIT and Apache2.
49