我正在尝试使用crossclip crate 将图像复制/粘贴到剪贴板/从剪贴板粘贴。所提供的将字符串设置到剪贴板的示例非常简单:
use crossclip::{Clipboard, SystemClipboard, Result};
fn main() -> Result<()> {
let clipboard = SystemClipboard::new()?;
clipboard.set_string_contents(String::from("Hello"))?;
println!("{}", clipboard.get_string_contents()?);
}
get_string_contents返回一个字符串。我假设要访问剪贴板中的图像,我需要get_content方法,在documentation中描述为:fn get_contents(
&self
) -> Result<(Vec<u8>, ClipboardContentType), ClipboardError>
如何从get_contents中打印出结果的类型,以便查看其是否为图像?
fn printTypeOfClipboardContents() -> Result<(), ClipboardError> {
let clipboard = SystemClipboard::new()?;
let teststuff = clipboard.get_contents();
//print the type of teststuff
Ok(())
}
最佳答案
在get_contents文档的正下方,您可以看到它说:
WARNING: Unimplemented, use get_string_contents
如果单击链接查看src,则可以看到整个函数定义为:
fn get_contents(&self) -> Result<(Vec<u8>, ClipboardContentType), ClipboardError> {
todo!("Unimplemented, use `get_string_contents`");
}
我得出的结论是,该库除纯文本外,尚不支持访问任何类型的数据的任何方式。
关于rust - 剪贴板的Rust Crossclip打印类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65064854/