Crates.io | clipboard-win |
lib.rs | clipboard-win |
version | 5.4.0 |
source | src |
created_at | 2015-07-12 15:24:51.887425 |
updated_at | 2024-07-07 07:05:57.611833 |
description | Provides simple way to interact with Windows clipboard. |
homepage | |
repository | https://github.com/DoumanAsh/clipboard-win |
max_upload_size | |
id | 2588 |
size | 86,439 |
This crate provide simple means to operate with Windows clipboard.
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.
All read and write access to Windows clipboard requires user to open it.
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);
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)