From 795726fe0465a0597fbe7cd9625af78f65d55518 Mon Sep 17 00:00:00 2001 From: rhysd Date: Mon, 20 Nov 2023 21:48:51 +0900 Subject: [PATCH] Bump clipboard-win from v3.0.2 to v4.5.0 --- Cargo.toml | 2 +- src/windows_clipboard.rs | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 19f53c6..bd80dfb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ x11 = ["x11-clipboard"] wayland = ["smithay-clipboard"] [target.'cfg(windows)'.dependencies] -clipboard-win = "3.0.2" +clipboard-win = "4.5.0" [target.'cfg(target_os = "macos")'.dependencies] objc = "0.2" diff --git a/src/windows_clipboard.rs b/src/windows_clipboard.rs index 6eb0ee2..134f91a 100644 --- a/src/windows_clipboard.rs +++ b/src/windows_clipboard.rs @@ -12,10 +12,30 @@ // See the License for the specific language governing permissions and // limitations under the License. -use clipboard_win::{get_clipboard_string, set_clipboard_string}; +use std::error::Error; +use std::fmt; + +use clipboard_win::{get_clipboard_string, set_clipboard_string, SystemError}; use crate::common::{ClipboardProvider, Result}; +// Wrap `clipboard_win::SystemError` since it does not implement `Error` trait +struct WindowsSystemError(SystemError); + +impl fmt::Debug for WindowsSystemError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} + +impl fmt::Display for WindowsSystemError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} + +impl Error for WindowsSystemError {} + pub struct WindowsClipboardContext; impl WindowsClipboardContext { @@ -26,10 +46,10 @@ impl WindowsClipboardContext { impl ClipboardProvider for WindowsClipboardContext { fn get_contents(&mut self) -> Result { - Ok(get_clipboard_string()?) + Ok(get_clipboard_string().map_err(WindowsSystemError)?) } fn set_contents(&mut self, data: String) -> Result<()> { - Ok(set_clipboard_string(&data)?) + Ok(set_clipboard_string(&data).map_err(WindowsSystemError)?) } }