Skip to content

Commit

Permalink
Bump clipboard-win from v3.0.2 to v4.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Nov 20, 2023
1 parent 54699fb commit 004464d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 23 additions & 3 deletions src/windows_clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `SystemError` since it does not implement `Error` trait
struct WrappedError(SystemError);

impl fmt::Debug for WrappedError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}

impl fmt::Display for WrappedError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}

impl Error for WrappedError {}

pub struct WindowsClipboardContext;

impl WindowsClipboardContext {
Expand All @@ -26,10 +46,10 @@ impl WindowsClipboardContext {

impl ClipboardProvider for WindowsClipboardContext {
fn get_contents(&mut self) -> Result<String> {
Ok(get_clipboard_string()?)
Ok(get_clipboard_string().map_err(WrappedError)?)
}

fn set_contents(&mut self, data: String) -> Result<()> {
Ok(set_clipboard_string(&data)?)
Ok(set_clipboard_string(&data).map_err(WrappedError)?)
}
}

0 comments on commit 004464d

Please sign in to comment.