#clipboard #winapi #format-time #windows

no-std clipboard-win

Provides simple way to interact with Windows clipboard

67 releases (stable)

5.4.0 Jul 7, 2024
5.3.0 Mar 14, 2024
5.0.0 Nov 22, 2023
4.5.0 Jan 8, 2023
0.9.3 Jul 16, 2015

#3 in Windows APIs

Download history 113898/week @ 2024-07-18 118470/week @ 2024-07-25 104547/week @ 2024-08-01 109870/week @ 2024-08-08 106276/week @ 2024-08-15 113277/week @ 2024-08-22 108316/week @ 2024-08-29 117294/week @ 2024-09-05 104910/week @ 2024-09-12 107834/week @ 2024-09-19 137139/week @ 2024-09-26 118007/week @ 2024-10-03 115217/week @ 2024-10-10 131914/week @ 2024-10-17 129317/week @ 2024-10-24 104830/week @ 2024-10-31

502,842 downloads per month
Used in 1,650 crates (43 directly)

BSL-1.0 license

77KB
1.5K SLoC

clipboard-win

Build Crates.io Docs.rs

This crate provide simple means to operate with Windows clipboard.

Note keeping Clipboard around:

In Windows Clipboard opens globally and only one application can set data onto format at the time.

Therefore as soon as operations are finished, user is advised to close Clipboard.

Clipboard

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

Usage

Manually lock clipboard

use clipboard_win::{Clipboard, formats, Getter, Setter};

const SAMPLE: &str = "MY loli sample ^^";

let _clip = Clipboard::new_attempts(10).expect("Open clipboard");
formats::Unicode.write_clipboard(&SAMPLE).expect("Write sample");

let mut output = String::new();

assert_eq!(formats::Unicode.read_clipboard(&mut output).expect("Read sample"), SAMPLE.len());
assert_eq!(output, SAMPLE);

//Efficiently re-use buffer ;)
output.clear();
assert_eq!(formats::Unicode.read_clipboard(&mut output).expect("Read sample"), SAMPLE.len());
assert_eq!(output, SAMPLE);

//Or take the same string twice?
assert_eq!(formats::Unicode.read_clipboard(&mut output).expect("Read sample"), SAMPLE.len());
assert_eq!(format!("{0}{0}", SAMPLE), output);

Simplified API

use clipboard_win::{formats, get_clipboard, set_clipboard};

let text = "my sample ><";

set_clipboard(formats::Unicode, text).expect("To set clipboard");
//Type is necessary as string can be stored in various storages
let result: String = get_clipboard(formats::Unicode).expect("To set clipboard");
assert_eq!(result, text)

Dependencies