refactor: make previous raw methods just allow specific mime types instead
This commit is contained in:
parent
e84ab6d2d8
commit
1b6efd066e
1 changed files with 22 additions and 8 deletions
30
src/lib.rs
30
src/lib.rs
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue