t_rust_less_lib/clipboard/
error.rs1use serde::{Deserialize, Serialize};
2use thiserror::Error;
3
4#[derive(Debug, Error, Serialize, Deserialize)]
5#[cfg_attr(feature = "with_specta", derive(specta::Type))]
6pub enum ClipboardError {
7 #[error("Clipboard not available")]
8 Unavailable,
9 #[error("Clipboard mutex error: {0}")]
10 Mutex(String),
11 #[error("Clipboard error: {0}")]
12 Other(String),
13}
14
15pub type ClipboardResult<T> = Result<T, ClipboardError>;
16
17#[cfg(all(unix, not(target_os = "android"), feature = "with_x11"))]
18impl From<std::ffi::NulError> for ClipboardError {
19 fn from(error: std::ffi::NulError) -> Self {
20 ClipboardError::Other(format!("{error}"))
21 }
22}
23
24#[cfg(all(unix, not(target_os = "android"), feature = "with_x11"))]
25impl From<std::env::VarError> for ClipboardError {
26 fn from(error: std::env::VarError) -> Self {
27 ClipboardError::Other(format!("{error}"))
28 }
29}
30
31#[cfg(all(unix, not(target_os = "android"), feature = "with_wayland"))]
32impl From<wayland_client::ConnectError> for ClipboardError {
33 fn from(error: wayland_client::ConnectError) -> Self {
34 match error {
35 wayland_client::ConnectError::NoCompositor => ClipboardError::Unavailable,
36 wayland_client::ConnectError::NoWaylandLib => ClipboardError::Unavailable,
37 err => ClipboardError::Other(format!("{err}")),
38 }
39 }
40}
41
42#[cfg(all(unix, not(target_os = "android"), feature = "with_wayland"))]
43impl From<wayland_client::globals::GlobalError> for ClipboardError {
44 fn from(error: wayland_client::globals::GlobalError) -> Self {
45 ClipboardError::Other(format!("{error}"))
46 }
47}
48
49#[cfg(all(unix, not(target_os = "android"), feature = "with_wayland"))]
50impl From<wayland_client::globals::BindError> for ClipboardError {
51 fn from(error: wayland_client::globals::BindError) -> Self {
52 ClipboardError::Other(format!("{error}"))
53 }
54}
55
56#[cfg(all(unix, not(target_os = "android"), feature = "with_wayland"))]
57impl From<wayland_client::DispatchError> for ClipboardError {
58 fn from(error: wayland_client::DispatchError) -> Self {
59 ClipboardError::Other(format!("{error}"))
60 }
61}
62
63impl<T> From<std::sync::PoisonError<T>> for ClipboardError {
64 fn from(error: std::sync::PoisonError<T>) -> Self {
65 ClipboardError::Mutex(format!("{error}"))
66 }
67}