pub struct ClipboardContext { /* private fields */ }
Implementations§
Source§impl ClipboardContext
impl ClipboardContext
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Examples found in repository?
More examples
examples/files.rs (line 4)
3fn main() {
4 let ctx = ClipboardContext::new().unwrap();
5
6 // change the file paths to your own
7 // let files = vec![
8 // "file:///home/parallels/clipboard-rs/Cargo.toml".to_string(),
9 // "file:///home/parallels/clipboard-rs/CHANGELOG.md".to_string(),
10 // ];
11
12 // ctx.set_files(files).unwrap();
13
14 let types = ctx.available_formats().unwrap();
15 println!("{:?}", types);
16
17 let has = ctx.has(ContentFormat::Files);
18 println!("has_files={}", has);
19
20 let files = ctx.get_files().unwrap_or_default();
21 println!("{:?}", files);
22}
examples/helloworld.rs (line 4)
3fn main() {
4 let ctx = ClipboardContext::new().unwrap();
5 let types = ctx.available_formats().unwrap();
6 println!("{:?}", types);
7
8 let has_rtf = ctx.has(ContentFormat::Rtf);
9 println!("has_rtf={}", has_rtf);
10
11 let rtf = ctx.get_rich_text().unwrap_or("".to_string());
12
13 println!("rtf={}", rtf);
14
15 let has_html = ctx.has(ContentFormat::Html);
16 println!("has_html={}", has_html);
17
18 let html = ctx.get_html().unwrap_or("".to_string());
19
20 println!("html={}", html);
21
22 let content = ctx.get_text().unwrap_or("".to_string());
23
24 println!("txt={}", content);
25}
examples/multi.rs (line 6)
5fn main() {
6 let ctx = ClipboardContext::new().unwrap();
7
8 let contents: Vec<ClipboardContent> = vec![
9 ClipboardContent::Text("hell@$#%^&U都98好的😊o Rust!!!".to_string()),
10 ClipboardContent::Rtf("\x1b[1m\x1b[4m\x1b[31mHello, Rust!\x1b[0m".to_string()),
11 ClipboardContent::Html("<html><body><h1>Hello, Rust!</h1></body></html>".to_string()),
12 ];
13
14 ctx.set(contents).unwrap();
15
16 let types = ctx.available_formats().unwrap();
17 println!("{:?}", types);
18
19 let read = ctx
20 .get(&[ContentFormat::Text, ContentFormat::Rtf, ContentFormat::Html])
21 .unwrap();
22
23 for c in read {
24 println!("{}", c.as_str().unwrap());
25 }
26}
Sourcepub fn new_with_options(options: ClipboardContextX11Options) -> Result<Self>
pub fn new_with_options(options: ClipboardContextX11Options) -> Result<Self>
Trait Implementations§
Source§impl Clipboard for ClipboardContext
impl Clipboard for ClipboardContext
Source§fn available_formats(&self) -> Result<Vec<String>>
fn available_formats(&self) -> Result<Vec<String>>
zh: 获得剪切板当前内容的所有格式
en: Get all formats of the current content in the clipboard
fn has(&self, format: ContentFormat) -> bool
Source§fn get_buffer(&self, format: &str) -> Result<Vec<u8>>
fn get_buffer(&self, format: &str) -> Result<Vec<u8>>
zh: 获得指定格式的数据,以字节数组形式返回
en: Get the data in the specified format in the clipboard as a byte array
Source§fn get_text(&self) -> Result<String>
fn get_text(&self) -> Result<String>
zh: 仅获得无格式纯文本,以字符串形式返回
en: Get plain text content in the clipboard as string
Source§fn get_rich_text(&self) -> Result<String>
fn get_rich_text(&self) -> Result<String>
zh: 获得剪贴板中的富文本内容,以字符串形式返回
en: Get the rich text content in the clipboard as string
Source§fn get_html(&self) -> Result<String>
fn get_html(&self) -> Result<String>
zh: 获得剪贴板中的html内容,以字符串形式返回
en: Get the html format content in the clipboard as string
fn get_image(&self) -> Result<RustImageData>
fn get_files(&self) -> Result<Vec<String>>
fn get(&self, formats: &[ContentFormat]) -> Result<Vec<ClipboardContent>>
fn set_buffer(&self, format: &str, buffer: Vec<u8>) -> Result<()>
fn set_text(&self, text: String) -> Result<()>
fn set_rich_text(&self, text: String) -> Result<()>
fn set_html(&self, html: String) -> Result<()>
fn set_image(&self, image: RustImageData) -> Result<()>
fn set_files(&self, files: Vec<String>) -> Result<()>
Auto Trait Implementations§
impl Freeze for ClipboardContext
impl RefUnwindSafe for ClipboardContext
impl Send for ClipboardContext
impl Sync for ClipboardContext
impl Unpin for ClipboardContext
impl UnwindSafe for ClipboardContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more