1use std::path::PathBuf;
3use std::sync::Arc;
4
5#[derive(Debug, Clone)]
7pub struct Clipboard {
8 pub reads: Vec<Kind>,
10 pub write: Option<Content>,
13}
14
15impl Clipboard {
16 pub fn new() -> Self {
18 Self {
19 reads: Vec::new(),
20 write: None,
21 }
22 }
23
24 pub fn merge(&mut self, other: &mut Self) {
26 self.reads.append(&mut other.reads);
27 self.write = other.write.take().or(self.write.take());
28 }
29}
30
31impl Default for Clipboard {
32 fn default() -> Self {
33 Self::new()
34 }
35}
36
37#[derive(Debug, Clone, PartialEq)]
39pub enum Event {
40 Read(Result<Arc<Content>, Error>),
42
43 Written(Result<(), Error>),
45}
46
47#[derive(Debug, Clone, PartialEq)]
49#[allow(missing_docs)]
50#[non_exhaustive]
51pub enum Content {
52 Text(String),
53 Html(String),
54 #[cfg(feature = "image")]
55 Image(Image),
56 Files(Vec<PathBuf>),
57}
58
59impl From<String> for Content {
60 fn from(text: String) -> Self {
61 Self::Text(text)
62 }
63}
64
65#[cfg(feature = "image")]
66impl From<Image> for Content {
67 fn from(image: Image) -> Self {
68 Self::Image(image)
69 }
70}
71
72impl From<Vec<PathBuf>> for Content {
73 fn from(files: Vec<PathBuf>) -> Self {
74 Self::Files(files)
75 }
76}
77
78#[derive(Debug, Clone, Copy, PartialEq, Eq)]
80#[allow(missing_docs)]
81#[non_exhaustive]
82pub enum Kind {
83 Text,
84 Html,
85 #[cfg(feature = "image")]
86 Image,
87 Files,
88}
89
90#[cfg(feature = "image")]
92#[derive(Debug, Clone, PartialEq)]
93pub struct Image {
94 pub rgba: crate::Bytes,
96
97 pub size: crate::Size<u32>,
99}
100
101#[derive(Debug, Clone, PartialEq)]
103pub enum Error {
104 ClipboardUnavailable,
106
107 ClipboardOccupied,
109
110 ContentNotAvailable,
114
115 ConversionFailure,
118
119 Unknown {
121 description: Arc<String>,
124 },
125}