GithubHelp home page GithubHelp logo

pcpthm / clipboard-win Goto Github PK

View Code? Open in Web Editor NEW

This project forked from doumanash/clipboard-win

0.0 1.0 0.0 130 KB

Rust win clipboard utilities

Home Page: https://crates.io/crates/clipboard-win

License: MIT License

Rust 100.00%

clipboard-win's Introduction

clipboard-win

Build Crates.io Docs.rs

Provides simple way to interact with Windows 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

use clipboard_win::Clipboard;

fn main() {
    Clipboard::new().unwrap().empty();
}

Set and get raw data

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

use clipboard_win::Clipboard;

use std::str;

fn main() {
    let text = "For my waifu!";
    Clipboard::new().unwrap().set_string(text);

    let mut result = String::new();
    Clipboard::new().unwrap().get_string(&mut result).unwrap();
    assert_eq!(text, result);
}

Set and get String shortcuts

use clipboard_win::{set_clipboard_string, get_clipboard_string};

use std::str;

fn main() {
    let text = "For my waifu!";
    set_clipboard_string(text).expect("Success");

    let result = get_clipboard_string().unwrap();
    assert_eq!(text, result);
}

clipboard-win's People

Contributors

aweinstock314 avatar doumanash avatar nox avatar rkarp avatar vamolessa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.