Skip to content

Commit

Permalink
Remove direct thiserror dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
complexspaces committed Apr 28, 2024
1 parent 83740b7 commit 610e29b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ image-data = ["core-graphics", "image", "windows-sys"]
wayland-data-control = ["wl-clipboard-rs"]

[dependencies]
thiserror = "1.0"

[dev-dependencies]
env_logger = "0.9.0"
Expand Down
21 changes: 14 additions & 7 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,24 @@ and conditions of the chosen license apply to this file.

#[cfg(feature = "image-data")]
use std::borrow::Cow;
use thiserror::Error;

/// An error that might happen during a clipboard operation.
///
/// Note that both the `Display` and the `Debug` trait is implemented for this type in such a way
/// that they give a short human-readable description of the error; however the documentation
/// gives a more detailed explanation for each error kind.
#[derive(Error)]
#[non_exhaustive]
pub enum Error {
/// The clipboard contents were not available in the requested format.
/// This could either be due to the clipboard being empty or the clipboard contents having
/// an incompatible format to the requested one (eg when calling `get_image` on text)
#[error("The clipboard contents were not available in the requested format or the clipboard is empty.")]
ContentNotAvailable,

/// The selected clipboard is not supported by the current configuration (system and/or environment).
///
/// This can be caused by a few conditions:
/// - Using the Primary clipboard with an older Wayland compositor (that doesn't support version 2)
/// - Using the Secondary clipboard on Wayland
#[error("The selected clipboard is not supported with the current system configuration.")]
ClipboardNotSupported,

/// The native clipboard is not accessible due to being held by an other party.
Expand All @@ -43,22 +39,33 @@ pub enum Error {
/// Note that it's OK to have multiple `Clipboard` instances. The underlying
/// implementation will make sure that the native clipboard is only
/// opened for transferring data and then closed as soon as possible.
#[error("The native clipboard is not accessible due to being held by an other party.")]
ClipboardOccupied,

/// The image or the text that was about the be transferred to/from the clipboard could not be
/// converted to the appropriate format.
#[error("The image or the text that was about the be transferred to/from the clipboard could not be converted to the appropriate format.")]
ConversionFailure,

/// Any error that doesn't fit the other error types.
///
/// The `description` field is only meant to help the developer and should not be relied on as a
/// means to identify an error case during runtime.
#[error("Unknown error while interacting with the clipboard: {description}")]
Unknown { description: String },
}

impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::ContentNotAvailable => f.write_str("The clipboard contents were not available in the requested format or the clipboard is empty."),
Error::ClipboardNotSupported => f.write_str("The selected clipboard is not supported with the current system configuration."),
Error::ClipboardOccupied => f.write_str("The native clipboard is not accessible due to being held by an other party."),
Error::ConversionFailure => f.write_str("The image or the text that was about the be transferred to/from the clipboard could not be converted to the appropriate format."),
Error::Unknown { description } => f.write_fmt(format_args!("Unknown error while interacting with the clipboard: {description}")),
}
}
}

impl std::error::Error for Error {}

impl std::fmt::Debug for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use Error::*;
Expand Down

0 comments on commit 610e29b

Please sign in to comment.