refactor: make previous raw methods just allow specific mime types instead

This commit is contained in:
Ashley Wulber 2024-03-26 17:01:52 -04:00
parent e84ab6d2d8
commit 1b6efd066e
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820

View file

@ -88,24 +88,38 @@ impl<T: 'static + Send + Clone> Clipboard<T> {
self.load_primary::<Text>().map(|t| t.0)
}
/// Load raw clipboard data.
/// Load clipboard data for sepecific mime types.
///
/// Loads content from a primary clipboard on a last observed seat.
pub fn load_raw(
pub fn load_mime<D: TryFrom<(Vec<u8>, MimeType)>>(
&self,
allowed: impl Into<Cow<'static, [MimeType]>>,
) -> Result<(Vec<u8>, MimeType)> {
self.load_inner(Target::Clipboard, allowed)
) -> Result<D> {
self.load_inner(Target::Clipboard, allowed).and_then(|d| {
D::try_from(d).map_err(|_| {
std::io::Error::new(
std::io::ErrorKind::Other,
"Failed to load data of the requested type.",
)
})
})
}
/// Load raw primary clipboard data.
/// Load primary clipboard data for specific mime types.
///
/// Loads content from a primary clipboard on a last observed seat.
pub fn load_primary_raw(
pub fn load_primary_mime<D: TryFrom<(Vec<u8>, MimeType)>>(
&self,
allowed: impl Into<Cow<'static, [MimeType]>>,
) -> Result<(Vec<u8>, MimeType)> {
self.load_inner(Target::Primary, allowed)
) -> Result<D> {
self.load_inner(Target::Primary, allowed).and_then(|d| {
D::try_from(d).map_err(|_| {
std::io::Error::new(
std::io::ErrorKind::Other,
"Failed to load data of the requested type.",
)
})
})
}
/// Store custom data to a clipboard.