Function wl_clipboard_rs::paste::get_contents
source · pub fn get_contents(
clipboard: ClipboardType,
seat: Seat<'_>,
mime_type: MimeType<'_>,
) -> Result<(PipeReader, String), Error>
Expand description
Retrieves the clipboard contents.
This function returns a tuple of the reading end of a pipe containing the clipboard contents and the actual MIME type of the contents.
If seat
is None
, uses an unspecified seat (it depends on the order returned by the
compositor). This is perfectly fine when only a single seat is present, so for most
configurations.
§Examples
use std::io::Read;
use wl_clipboard_rs::{paste::{get_contents, ClipboardType, Error, MimeType, Seat}};
let result = get_contents(ClipboardType::Regular, Seat::Unspecified, MimeType::Any);
match result {
Ok((mut pipe, mime_type)) => {
println!("Got data of the {} MIME type", &mime_type);
let mut contents = vec![];
pipe.read_to_end(&mut contents)?;
println!("Read {} bytes of data", contents.len());
}
Err(Error::NoSeats) | Err(Error::ClipboardEmpty) | Err(Error::NoMimeType) => {
// The clipboard is empty, nothing to worry about.
}
Err(err) => Err(err)?
}