refactor: avoid breaking changes and update smithay-clipboard
This commit is contained in:
parent
6c41143f5c
commit
886f430414
4 changed files with 37 additions and 37 deletions
24
src/lib.rs
24
src/lib.rs
|
|
@ -67,51 +67,51 @@ impl Clipboard<platform::Clipboard> {
|
|||
}
|
||||
|
||||
pub fn read(&self) -> Result<String, Box<dyn Error>> {
|
||||
self.raw.read_text()
|
||||
self.raw.read()
|
||||
}
|
||||
|
||||
pub fn write(&mut self, contents: String) -> Result<(), Box<dyn Error>> {
|
||||
self.raw.write_text(contents)
|
||||
self.raw.write(contents)
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: ClipboardProvider> Clipboard<C> {
|
||||
pub fn read_primary(&self) -> Option<Result<String, Box<dyn Error>>> {
|
||||
self.raw.read_primary_text()
|
||||
self.raw.read_primary()
|
||||
}
|
||||
|
||||
pub fn write_primary(
|
||||
&mut self,
|
||||
contents: String,
|
||||
) -> Option<Result<(), Box<dyn Error>>> {
|
||||
self.raw.write_primary_text(contents)
|
||||
self.raw.write_primary(contents)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ClipboardProvider {
|
||||
fn read_text(&self) -> Result<String, Box<dyn Error>>;
|
||||
fn read(&self) -> Result<String, Box<dyn Error>>;
|
||||
|
||||
fn write_text(&mut self, contents: String) -> Result<(), Box<dyn Error>>;
|
||||
fn write(&mut self, contents: String) -> Result<(), Box<dyn Error>>;
|
||||
|
||||
fn read_primary_text(&self) -> Option<Result<String, Box<dyn Error>>> {
|
||||
fn read_primary(&self) -> Option<Result<String, Box<dyn Error>>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn write_primary_text(
|
||||
fn write_primary(
|
||||
&mut self,
|
||||
_contents: String,
|
||||
) -> Option<Result<(), Box<dyn Error>>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn read<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>>
|
||||
fn read_data<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>>
|
||||
where
|
||||
ClipboardLoadData<T>: platform::InnerAllowedMimeTypes,
|
||||
{
|
||||
None
|
||||
}
|
||||
|
||||
fn write<T: Send + Sync + 'static>(
|
||||
fn write_data<T: Send + Sync + 'static>(
|
||||
&mut self,
|
||||
_contents: ClipboardStoreData<T>,
|
||||
) -> Option<Result<(), Box<dyn Error>>>
|
||||
|
|
@ -121,14 +121,14 @@ pub trait ClipboardProvider {
|
|||
None
|
||||
}
|
||||
|
||||
fn read_primary<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>>
|
||||
fn read_primary_data<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>>
|
||||
where
|
||||
ClipboardLoadData<T>: platform::InnerAllowedMimeTypes,
|
||||
{
|
||||
None
|
||||
}
|
||||
|
||||
fn write_primary<T: Send + Sync + 'static>(
|
||||
fn write_primary_data<T: Send + Sync + 'static>(
|
||||
&mut self,
|
||||
_contents: ClipboardStoreData<T>,
|
||||
) -> Option<Result<(), Box<dyn Error>>>
|
||||
|
|
|
|||
|
|
@ -19,53 +19,53 @@ pub enum Clipboard {
|
|||
}
|
||||
|
||||
impl ClipboardProvider for Clipboard {
|
||||
fn read_text(&self) -> Result<String, Box<dyn Error>> {
|
||||
fn read(&self) -> Result<String, Box<dyn Error>> {
|
||||
match self {
|
||||
Clipboard::Wayland(c) => c.read_text(),
|
||||
Clipboard::Wayland(c) => c.read(),
|
||||
Clipboard::X11(c) => c.read().map_err(Box::from),
|
||||
}
|
||||
}
|
||||
|
||||
fn write_text(&mut self, contents: String) -> Result<(), Box<dyn Error>> {
|
||||
fn write(&mut self, contents: String) -> Result<(), Box<dyn Error>> {
|
||||
match self {
|
||||
Clipboard::Wayland(c) => c.write_text(contents),
|
||||
Clipboard::Wayland(c) => c.write(contents),
|
||||
Clipboard::X11(c) => c.write(contents).map_err(Box::from),
|
||||
}
|
||||
}
|
||||
|
||||
fn read_primary_text(&self) -> Option<Result<String, Box<dyn Error>>> {
|
||||
fn read_primary(&self) -> Option<Result<String, Box<dyn Error>>> {
|
||||
match self {
|
||||
Clipboard::Wayland(c) => Some(c.read_primary_text()),
|
||||
Clipboard::Wayland(c) => Some(c.read_primary()),
|
||||
Clipboard::X11(c) => Some(c.read_primary().map_err(Box::from)),
|
||||
}
|
||||
}
|
||||
|
||||
fn write_primary_text(
|
||||
fn write_primary(
|
||||
&mut self,
|
||||
contents: String,
|
||||
) -> Option<Result<(), Box<dyn Error>>> {
|
||||
match self {
|
||||
Clipboard::Wayland(c) => Some(c.write_primary_text(contents)),
|
||||
Clipboard::Wayland(c) => Some(c.write_primary(contents)),
|
||||
Clipboard::X11(c) => {
|
||||
Some(c.write_primary(contents).map_err(Box::from))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn read<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>>
|
||||
fn read_data<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>>
|
||||
where
|
||||
ClipboardLoadData<T>: InnerAllowedMimeTypes,
|
||||
{
|
||||
match self {
|
||||
Clipboard::Wayland(c) => {
|
||||
let ret = c.read::<ClipboardLoadData<T>>();
|
||||
let ret = c.read_data::<ClipboardLoadData<T>>();
|
||||
Some(ret.map(|ret| ret.0))
|
||||
}
|
||||
Clipboard::X11(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn write<T: Send + Sync + 'static>(
|
||||
fn write_data<T: Send + Sync + 'static>(
|
||||
&mut self,
|
||||
contents: ClipboardStoreData<T>,
|
||||
) -> Option<Result<(), Box<dyn Error>>>
|
||||
|
|
@ -74,26 +74,26 @@ impl ClipboardProvider for Clipboard {
|
|||
{
|
||||
match self {
|
||||
Clipboard::Wayland(c) => {
|
||||
Some(c.write::<ClipboardStoreData<T>>(contents))
|
||||
Some(c.write_data::<ClipboardStoreData<T>>(contents))
|
||||
}
|
||||
Clipboard::X11(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn read_primary<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>>
|
||||
fn read_primary_data<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>>
|
||||
where
|
||||
ClipboardLoadData<T>: InnerAllowedMimeTypes,
|
||||
{
|
||||
match self {
|
||||
Clipboard::Wayland(c) => {
|
||||
let ret = c.read_primary::<ClipboardLoadData<T>>();
|
||||
let ret = c.read_primary_data::<ClipboardLoadData<T>>();
|
||||
Some(ret.map(|ret| ret.0))
|
||||
}
|
||||
Clipboard::X11(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn write_primary<T: Send + Sync + 'static>(
|
||||
fn write_primary_data<T: Send + Sync + 'static>(
|
||||
&mut self,
|
||||
contents: ClipboardStoreData<T>,
|
||||
) -> Option<Result<(), Box<dyn Error>>>
|
||||
|
|
@ -102,7 +102,7 @@ impl ClipboardProvider for Clipboard {
|
|||
{
|
||||
match self {
|
||||
Clipboard::Wayland(c) => {
|
||||
Some(c.write_primary::<ClipboardStoreData<T>>(contents))
|
||||
Some(c.write_primary_data::<ClipboardStoreData<T>>(contents))
|
||||
}
|
||||
Clipboard::X11(_) => None,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,5 +10,5 @@ documentation = "https://docs.rs/clipboard_wayland"
|
|||
keywords = ["clipboard", "wayland"]
|
||||
|
||||
[dependencies]
|
||||
smithay-clipboard = { git = "https://github.com/wash2/smithay-clipboard", branch = "mime-types" }
|
||||
smithay-clipboard = { git = "https://github.com/pop-os/smithay-clipboard", tag = "pop-mime-types" }
|
||||
# smithay-clipboard = { path = "../../smithay-clipboard" }
|
||||
|
|
|
|||
|
|
@ -33,21 +33,21 @@ impl Clipboard {
|
|||
Clipboard { context }
|
||||
}
|
||||
|
||||
pub fn read_text(&self) -> Result<String, Box<dyn Error>> {
|
||||
pub fn read(&self) -> Result<String, Box<dyn Error>> {
|
||||
Ok(self.context.lock().unwrap().load_text()?)
|
||||
}
|
||||
|
||||
pub fn read_primary_text(&self) -> Result<String, Box<dyn Error>> {
|
||||
pub fn read_primary(&self) -> Result<String, Box<dyn Error>> {
|
||||
Ok(self.context.lock().unwrap().load_primary_text()?)
|
||||
}
|
||||
|
||||
pub fn write_text(&mut self, data: String) -> Result<(), Box<dyn Error>> {
|
||||
pub fn write(&mut self, data: String) -> Result<(), Box<dyn Error>> {
|
||||
self.context.lock().unwrap().store_text(data);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn write_primary_text(
|
||||
pub fn write_primary(
|
||||
&mut self,
|
||||
data: String,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
|
|
@ -56,7 +56,7 @@ impl Clipboard {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn write<T: AsMimeTypes + Send + Sync + 'static>(
|
||||
pub fn write_data<T: AsMimeTypes + Send + Sync + 'static>(
|
||||
&mut self,
|
||||
data: T,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
|
|
@ -65,7 +65,7 @@ impl Clipboard {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn write_primary<T: AsMimeTypes + Send + Sync + 'static>(
|
||||
pub fn write_primary_data<T: AsMimeTypes + Send + Sync + 'static>(
|
||||
&mut self,
|
||||
data: T,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
|
|
@ -74,13 +74,13 @@ impl Clipboard {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn read<T: AllowedMimeTypes + 'static>(
|
||||
pub fn read_data<T: AllowedMimeTypes + 'static>(
|
||||
&self,
|
||||
) -> Result<T, Box<dyn Error>> {
|
||||
Ok(self.context.lock().unwrap().load()?)
|
||||
}
|
||||
|
||||
pub fn read_primary<T: AllowedMimeTypes + 'static>(
|
||||
pub fn read_primary_data<T: AllowedMimeTypes + 'static>(
|
||||
&self,
|
||||
) -> Result<T, Box<dyn Error>> {
|
||||
Ok(self.context.lock().unwrap().load_primary()?)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue