[−][src]Crate clipboard_win
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.
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 returnsio::error
with kindInvalidData
Re-exports
pub use raw::register_format; |
Modules
formats | Standard clipboard formats. |
image | Image module |
raw | Raw bindings to Windows clipboard. |
Structs
Clipboard | Clipboard accessor. |
Functions
get_clipboard_string | Shortcut to retrieve string from clipboard. |
set_clipboard_string | Shortcut to set string onto clipboard. |