#Windows #winapi #clipboard

clipboard-win

Provides simple way to interact with Windows clipboard

44 releases (27 stable)

✓ Uses Rust 2018 edition

3.0.2 May 1, 2020
3.0.1 Feb 22, 2020
3.0.0-alpha.1 Jun 17, 2019
2.2.0 May 30, 2019
0.9.3 Jul 16, 2015

#3 in Windows APIs

Download history 2991/week @ 2020-01-25 2261/week @ 2020-02-01 3060/week @ 2020-02-08 2581/week @ 2020-02-15 3073/week @ 2020-02-22 2555/week @ 2020-02-29 2362/week @ 2020-03-07 3201/week @ 2020-03-14 3016/week @ 2020-03-21 2906/week @ 2020-03-28 3316/week @ 2020-04-04 3182/week @ 2020-04-11 3126/week @ 2020-04-18 3080/week @ 2020-04-25 3527/week @ 2020-05-02 2658/week @ 2020-05-09

12,367 downloads per month
Used in 120 crates (6 directly)

MIT license

39KB
656 lines

clipboard-win

Build Crates.io Docs.rs

Provides simple way to interact with Windows clipboard.

Clipboard

All read and write access to Windows clipboard requires user to open it.

For your convenience you can use Clipboard struct that opens it at creation and closes on its drop.

Alternatively you can access all functionality directly through raw module.

Below you can find examples of usage.

Empty clipboard

extern crate clipboard_win;

use clipboard_win::Clipboard;

fn main() {
    Clipboard::new().unwrap().empty();
}

Set and get raw data

extern crate clipboard_win;
use clipboard_win::formats;

use clipboard_win::Clipboard;

use std::str;

fn main() {
    let text = "For my waifu!\0"; //For text we need to pass C-like string
    Clipboard::new().unwrap().set(formats::CF_TEXT, text.as_bytes());

    let mut buffer = [0u8; 52];
    let result = Clipboard::new().unwrap().get(formats::CF_TEXT, &mut buffer).unwrap();
    assert_eq!(str::from_utf8(&buffer[..result]).unwrap(), text);
}

Set and get String

extern crate clipboard_win;
use clipboard_win::Clipboard;

use std::str;

fn main() {
    let text = "For my waifu!";
    Clipboard::new().unwrap().set_string(text);

    let mut result = String::new();
    Clipboard::new().unwrap().get_string(&mut result).unwrap();
    assert_eq!(text, result);
}

Set and get String shortcuts

extern crate clipboard_win;
use clipboard_win::{set_clipboard_string, get_clipboard_string};

use std::str;

fn main() {
    let text = "For my waifu!";
    set_clipboard_string(text).expect("Success");

    let result = get_clipboard_string().unwrap();
    assert_eq!(text, result);
}

Dependencies

~33KB