百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

clipboard-rs

> 数据库
开源

跨平台剪贴板 API(文本|图片|富文本|html|文件|监听变化) Windows,MacOS,Linux

176 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

跨平台剪贴板 API(文本|图片|富文本|html|文件|监听变化) Windows,MacOS,Linux

clipboard-rs

clipboard-rs is a cross-platform library written in Rust for getting and setting the system-level clipboard content. It supports Linux, Windows, and MacOS.

简体中文

Function Support

  • Plain text
  • Html
  • Rich text
  • Image (In PNG format)
  • File (In file-uri-list format)
  • Any type (by specifying the type identifier) can be obtained through the available_formats method

Platform Support Type Comparison Table

Type Windows macOS Linux(X11) iOS(Beta) Android(WIP)
Plain Text ✅ ✅ ✅ ✅
HTML ✅ ✅ ✅ ✅
RTF ✅ ✅ ✅ ✅
Image PNG(preferred)/DIBV5 PNG(preferred)/TIFF PNG PNG
File List ✅ ✅ ✅ ❌
Custom Type ✅ ✅ ✅ ✅
Watch Changes ✅ ✅ ✅ ✅

Development Plan

  • MacOS Support
  • Linux Support (x11)
  • Windows Support
  • iOS Support (Beta)
  • Android Support ()

Usage

Add the following content to your Cargo.toml:

toml
[dependencies]
clipboard-rs = "0.3.5"

CHANGELOG

Examples

All Usage Examples

Examples

Simple Read and Write

…

Reading Images

rust
use clipboard_rs::{common::RustImage, Clipboard, ClipboardContext};

const TMP_PATH: &str = "/tmp/";

fn main() {
	let ctx = ClipboardContext::new().unwrap();
	let types = ctx.available_formats().unwrap();
	println!("{:?}", types);

	let img = ctx.get_image();

	match img {
		Ok(img) => {
			img.save_to_path(format!("{}test.png", TMP_PATH).as_str())
				.unwrap();

			let resize_img = img.thumbnail(300, 300).unwrap();

			resize_img
				.save_to_path(format!("{}test_thumbnail.png", TMP_PATH).as_str())
				.unwrap();
		}
		Err(err) => {
			println!("err={}", err);
		}
	}
}

Reading Any Format

rust
use clipboard_rs::{Clipboard, ClipboardContext};

fn main() {
    let ctx = ClipboardContext::new().unwrap();
    let types = ctx.available_formats().unwrap();
    println!("{:?}", types);

    let buffer = ctx.get_buffer("public.html").unwrap();

    let string = String::from_utf8(buffer).unwrap();

    println!("{}", string);
}

Listening to Clipboard Changes

…

X11 - Clipboard Read Timeout

By default, in X11 clipboard-rs implements a read timeout of 500 ms. You can override or disable this timeout by creating ClipboardContext using new_with_options:

rust
#[cfg(unix)]
fn setup_clipboard() -> ClipboardContext {
	ClipboardContext::new_with_options(ClipboardContextX11Options { read_timeout: None }).unwrap()
}

#[cfg(not(unix))]
fn setup_clipboard(ctx: &mut ClipboardContext) -> ClipboardContext{
	ClipboardContext::new().unwrap()
}

Contributing

You are welcome to submit PRs and issues and contribute your code or ideas to the project. Due to my limited level, the library may also have bugs. You are welcome to point them out and I will modify them as soon as possible.

Thanks

  • API design is inspired by electron
  • Linux part of the project code is referenced from x11-clipboard

Contract

if you have any questions, you can contact me by email: [email protected]

Chinese users can also contact me by wechatNo: uniq_idx_church_lynn

License

This project is licensed under the MIT License. See the LICENSE file for details.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rustclipboardcross-platformelectronrust

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库