feat: add methods for loading raw data

This commit is contained in:
Ashley Wulber 2024-03-14 16:42:24 -04:00
parent 5dd795d463
commit 71df657777
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
9 changed files with 153 additions and 63 deletions

View file

@ -13,6 +13,7 @@
// limitations under the License.
use std::{
borrow::Cow,
error::Error,
ffi::c_void,
sync::{Arc, Mutex},
@ -85,4 +86,38 @@ impl Clipboard {
) -> Result<T, Box<dyn Error>> {
Ok(self.context.lock().unwrap().load_primary()?)
}
pub fn read_primary_raw(
&self,
allowed: Vec<String>,
) -> Result<(Vec<u8>, String), Box<dyn Error>> {
Ok(self
.context
.lock()
.unwrap()
.load_primary_raw(
allowed
.into_iter()
.map(|s| MimeType::from(Cow::Owned(s)))
.collect::<Vec<_>>(),
)
.map(|(d, m)| (d, m.to_string()))?)
}
pub fn read_raw(
&self,
allowed: Vec<String>,
) -> Result<(Vec<u8>, String), Box<dyn Error>> {
Ok(self
.context
.lock()
.unwrap()
.load_raw(
allowed
.into_iter()
.map(|s| MimeType::from(Cow::Owned(s)))
.collect::<Vec<_>>(),
)
.map(|(d, m)| (d, m.to_string()))?)
}
}