#Windows #winapi #clipboard

clipboard-win

Provides simple way to interact with Windows clipboard

40 releases (24 stable)

✓ Uses Rust 2018 edition

2.2.0 May 30, 2019
2.1.2 Apr 1, 2018
2.1.1 Dec 18, 2017
2.0.1 Jun 6, 2017
0.9.3 Jul 16, 2015

#1 in #winapi

Download history 642/week @ 2019-02-14 614/week @ 2019-02-21 862/week @ 2019-02-28 760/week @ 2019-03-07 1012/week @ 2019-03-14 1045/week @ 2019-03-21 716/week @ 2019-03-28 812/week @ 2019-04-04 739/week @ 2019-04-11 1487/week @ 2019-04-18 1150/week @ 2019-04-25 935/week @ 2019-05-02 964/week @ 2019-05-09 763/week @ 2019-05-16 614/week @ 2019-05-23

3,983 downloads per month
Used in 42 crates (5 directly)

MIT license

33KB
555 lines

clipboard-win

Build status 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 result = Clipboard::new().unwrap().get_string().unwrap();
    assert_eq!(text, result);
}

Feature list

  • utf16error - Uses non-lossy conversion from UTF-16 to UTF-8. On error returns io::error with kind InvalidData

Dependencies

~537KB