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/image.rs (line 4)
3 4 5 6 7 8 9 10 11 12 13 14 15
fn main() {
let ctx = ClipboardContext::new().unwrap();
let types = ctx.available_formats().unwrap();
println!("{:?}", types);
let img = ctx.get_image().unwrap();
img.save_to_path("/tmp/test.png").unwrap();
let resize_img = img.thumbnail(300, 300).unwrap();
resize_img.save_to_path("/tmp/test_thumbnail.png").unwrap();
}examples/watch_change.rs (line 5)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let ctx = ClipboardContext::new().unwrap();
let mut watcher = ClipboardWatcherContext::new().unwrap();
watcher.add_handler(Box::new(move || {
let content = ctx.get_text().unwrap();
println!("read:{}", content);
}));
let watcher_shutdown = watcher.get_shutdown_channel();
thread::spawn(move || {
thread::sleep(Duration::from_secs(5));
println!("stop watch!");
watcher_shutdown.stop();
});
println!("start watch!");
watcher.start_watch();
}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();
println!("rtf={}", rtf);
let has_html = ctx.has(ContentFormat::Html);
println!("has_html={}", has_html);
let html = ctx.get_html().unwrap();
println!("html={}", html);
let content = ctx.get_text().unwrap();
println!("txt={}", content);
}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 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<()>
Auto Trait Implementations§
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