Struct clipboard_rs::ClipboardContext
source · 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)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
fn main() {
let ctx = ClipboardContext::new().unwrap();
// change the file paths to your own
// let files = vec![
// "file:///home/parallels/clipboard-rs/Cargo.toml".to_string(),
// "file:///home/parallels/clipboard-rs/CHANGELOG.md".to_string(),
// ];
// ctx.set_files(files).unwrap();
let types = ctx.available_formats().unwrap();
println!("{:?}", types);
let has = ctx.has(ContentFormat::Files);
println!("has_files={}", has);
let files = ctx.get_files().unwrap_or_default();
println!("{:?}", files);
}examples/helloworld.rs (line 4)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
let ctx = ClipboardContext::new().unwrap();
let types = ctx.available_formats().unwrap();
println!("{:?}", types);
let has_rtf = ctx.has(ContentFormat::Rtf);
println!("has_rtf={}", has_rtf);
let rtf = ctx.get_rich_text().unwrap_or("".to_string());
println!("rtf={}", rtf);
let has_html = ctx.has(ContentFormat::Html);
println!("has_html={}", has_html);
let html = ctx.get_html().unwrap_or("".to_string());
println!("html={}", html);
let content = ctx.get_text().unwrap_or("".to_string());
println!("txt={}", content);
}examples/multi.rs (line 6)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
fn main() {
let ctx = ClipboardContext::new().unwrap();
let contents: Vec<ClipboardContent> = vec![
ClipboardContent::Text("hell@$#%^&U都98好的😊o Rust!!!".to_string()),
ClipboardContent::Rtf("\x1b[1m\x1b[4m\x1b[31mHello, Rust!\x1b[0m".to_string()),
ClipboardContent::Html("<html><body><h1>Hello, Rust!</h1></body></html>".to_string()),
];
ctx.set(contents).unwrap();
let types = ctx.available_formats().unwrap();
println!("{:?}", types);
let read = ctx
.get(&[ContentFormat::Text, ContentFormat::Rtf, ContentFormat::Html])
.unwrap();
for c in read {
println!("{}", c.as_str().unwrap());
}
}examples/image.rs (line 19)
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
fn main() {
let ctx = ClipboardContext::new().unwrap();
let types = ctx.available_formats().unwrap();
println!("{:?}", types);
let img = ctx.get_image();
match img {
Ok(img) => {
let _ = img
.save_to_path(format!("{}test.png", TMP_PATH).as_str())
.map_err(|e| println!("save test.png err={}", e));
let resize_img = img
.thumbnail(300, 300)
.map_err(|e| println!("thumbnail err={}", e))
.unwrap();
let _ = resize_img
.save_to_path(format!("{}test_thumbnail.png", TMP_PATH).as_str())
.map_err(|e| println!("save test_thumbnail.png err={}", e));
}
Err(err) => {
println!("err={}", err);
}
}
}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