| Crates.io | clipkeeper |
| lib.rs | clipkeeper |
| version | 0.1.1 |
| created_at | 2025-11-02 12:44:09.426351+00 |
| updated_at | 2025-11-02 14:38:00.347379+00 |
| description | A Rust library for saving and restoring Windows clipboard contents with full format support |
| homepage | https://github.com/initialencounter/clipkeeper |
| repository | https://github.com/initialencounter/clipkeeper |
| max_upload_size | |
| id | 1913090 |
| size | 25,245 |
一个用于保存和恢复 Windows 剪贴板内容的 Rust 库。
将以下内容添加到 Cargo.toml:
[dependencies]
clipkeeper = "0.1.0"
use clipkeeper::{
get_windows_clipboard_snapshot,
restore_windows_clipboard_snapshot,
WindowsClipboardSnapshot,
};
fn main() -> anyhow::Result<()> {
// 1. 获取当前剪贴板快照
let snapshot = get_windows_clipboard_snapshot()?;
println!("捕获了 {} 个格式", snapshot.formats.len());
// 2. 保存到文件(默认路径:~AppData/Roaming/clipkeeper/clipboard_snapshot.json)
let file_path = snapshot.save_to_file(None)?;
println!("已保存到: {:?}", file_path);
// 3. 从文件加载快照
let loaded_snapshot = WindowsClipboardSnapshot::load_from_file(None)?;
// 4. 恢复剪贴板
restore_windows_clipboard_snapshot(&loaded_snapshot)?;
println!("剪贴板已恢复");
Ok(())
}
use std::path::PathBuf;
// 保存到自定义路径
let custom_path = PathBuf::from("my_clipboard.json");
snapshot.save_to_file(Some(custom_path.clone()))?;
// 从自定义路径加载
let snapshot = WindowsClipboardSnapshot::load_from_file(Some(custom_path))?;
cargo run --example basic
AGPL-3.0