chore: add more impls of clipboard methods
This commit is contained in:
parent
71df657777
commit
20e7cbedf5
2 changed files with 60 additions and 0 deletions
|
|
@ -27,6 +27,16 @@ pub trait AsMimeTypes {
|
||||||
fn as_bytes(&self, mime_type: &str) -> Option<Cow<'static, [u8]>>;
|
fn as_bytes(&self, mime_type: &str) -> Option<Cow<'static, [u8]>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: AsMimeTypes + ?Sized> AsMimeTypes for Box<T> {
|
||||||
|
fn available(&self) -> Cow<'static, [String]> {
|
||||||
|
self.as_ref().available()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_bytes(&self, mime_type: &str) -> Option<Cow<'static, [u8]>> {
|
||||||
|
self.as_ref().as_bytes(mime_type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Data that can be stored to the clipboard.
|
/// Data that can be stored to the clipboard.
|
||||||
pub struct ClipboardStoreData<T> {
|
pub struct ClipboardStoreData<T> {
|
||||||
/// Clipboard data.
|
/// Clipboard data.
|
||||||
|
|
|
||||||
50
src/lib.rs
50
src/lib.rs
|
|
@ -88,6 +88,56 @@ impl<C: ClipboardProvider> PlatformClipboard<C> {
|
||||||
) -> Option<Result<(), Box<dyn Error>>> {
|
) -> Option<Result<(), Box<dyn Error>>> {
|
||||||
self.raw.write_primary(contents)
|
self.raw.write_primary(contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn read_data<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>>
|
||||||
|
where
|
||||||
|
T: mime::AllowedMimeTypes,
|
||||||
|
{
|
||||||
|
self.raw.read_data()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_data<T: Send + Sync + 'static>(
|
||||||
|
&mut self,
|
||||||
|
contents: ClipboardStoreData<T>,
|
||||||
|
) -> Option<Result<(), Box<dyn Error>>>
|
||||||
|
where
|
||||||
|
T: mime::AsMimeTypes,
|
||||||
|
{
|
||||||
|
self.raw.write_data(contents)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_primary_data<T: 'static>(
|
||||||
|
&self,
|
||||||
|
) -> Option<Result<T, Box<dyn Error>>>
|
||||||
|
where
|
||||||
|
T: mime::AllowedMimeTypes,
|
||||||
|
{
|
||||||
|
self.raw.read_primary_data()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_primary_raw(
|
||||||
|
&self,
|
||||||
|
allowed: Vec<String>,
|
||||||
|
) -> Option<Result<(Vec<u8>, String), Box<dyn Error>>> {
|
||||||
|
self.raw.read_primary_raw(allowed)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_raw(
|
||||||
|
&self,
|
||||||
|
allowed: Vec<String>,
|
||||||
|
) -> Option<Result<(Vec<u8>, String), Box<dyn Error>>> {
|
||||||
|
self.raw.read_raw(allowed)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_primary_data<T: Send + Sync + 'static>(
|
||||||
|
&mut self,
|
||||||
|
contents: ClipboardStoreData<T>,
|
||||||
|
) -> Option<Result<(), Box<dyn Error>>>
|
||||||
|
where
|
||||||
|
T: mime::AsMimeTypes,
|
||||||
|
{
|
||||||
|
self.raw.write_primary_data(contents)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ClipboardProvider {
|
pub trait ClipboardProvider {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue