Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/doumanash/clipboard-win
Rust win clipboard utilities
https://github.com/doumanash/clipboard-win
clipboard winapi
Last synced: 10 days ago
JSON representation
Rust win clipboard utilities
- Host: GitHub
- URL: https://github.com/doumanash/clipboard-win
- Owner: DoumanAsh
- License: bsl-1.0
- Created: 2015-07-12T14:19:27.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-04-16T12:25:25.000Z (7 months ago)
- Last Synced: 2024-05-02T00:09:59.032Z (6 months ago)
- Topics: clipboard, winapi
- Language: Rust
- Homepage: https://crates.io/crates/clipboard-win
- Size: 164 KB
- Stars: 49
- Watchers: 6
- Forks: 13
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
clipboard-win
====================![Build](https://github.com/DoumanAsh/clipboard-win/workflows/Rust/badge.svg)
[![Crates.io](https://img.shields.io/crates/v/clipboard-win.svg)](https://crates.io/crates/clipboard-win)
[![Docs.rs](https://docs.rs/clipboard-win/badge.svg)](https://docs.rs/clipboard-win/*/x86_64-pc-windows-msvc/clipboard_win/)This crate provide simple means to operate with Windows clipboard.
# Note keeping Clipboard around:
In Windows [Clipboard](struct.Clipboard.html) 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](struct.Clipboard.html).
# Clipboard
All read and write access to Windows clipboard requires user to open it.
# Usage
## Manually lock clipboard
```rust
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
```rust
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)
```