1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use crate::platform_impl::Clipboard as ClipboardPlatform;
#[derive(Debug, Clone, Default)]
pub struct Clipboard(ClipboardPlatform);
impl Clipboard {
pub fn new() -> Self {
Self::default()
}
pub fn write_text(&mut self, s: impl AsRef<str>) {
self.0.write_text(s);
}
pub fn read_text(&self) -> Option<String> {
self.0.read_text()
}
}
pub(crate) type FormatId = &'static str;
#[derive(Debug, Clone)]
pub(crate) struct ClipboardFormat {
pub(crate) identifier: FormatId,
pub(crate) data: Vec<u8>,
}
impl ClipboardFormat {
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub const TEXT: &'static str = "public.utf8-plain-text";
#[cfg(any(target_os = "windows", target_os = "android"))]
pub const TEXT: &'static str = "text/plain";
#[cfg(target_os = "linux")]
pub const TEXT: &'static str = "UTF8_STRING";
}
impl ClipboardFormat {
pub fn new(identifier: FormatId, data: impl Into<Vec<u8>>) -> Self {
let data = data.into();
ClipboardFormat { identifier, data }
}
}
impl From<String> for ClipboardFormat {
fn from(src: String) -> ClipboardFormat {
let data = src.into_bytes();
ClipboardFormat::new(ClipboardFormat::TEXT, data)
}
}
impl From<&str> for ClipboardFormat {
fn from(src: &str) -> ClipboardFormat {
src.to_string().into()
}
}