Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUST

rust copy to clipboard

//using https://docs.rs/cli-clipboard/latest/cli_clipboard crate 

use cli_clipboard::{ClipboardContext, ClipboardProvider};

let mut ctx = ClipboardContext::new().unwrap();
let the_string = "Hello, world!";
ctx.set_contents(the_string.to_owned()).unwrap();
assert_eq!(ctx.get_contents().unwrap(), the_string);
ctx.clear();
// clearing the clipboard causes get_contents to return Err on macos and windows
if cfg!(any(windows, target_os = "macos")) {
   if ctx.get_contents().is_ok() {
       panic!("Should be Err");
   }
} else {
   assert_eq!(ctx.get_contents().unwrap(), "");
}
 
PREVIOUS NEXT
Tagged: #rust #copy #clipboard
ADD COMMENT
Topic
Name
4+1 =