Struct ClipboardContext

Source
pub struct ClipboardContext { /* private fields */ }

Implementations§

Source§

impl ClipboardContext

Source

pub fn new() -> Result<Self>

Examples found in repository?
examples/watch_change.rs (line 12)
11	pub fn new() -> Self {
12		let ctx = ClipboardContext::new().unwrap();
13		Manager { ctx }
14	}
More examples
Hide additional examples
examples/buffer.rs (line 4)
3fn main() {
4	let ctx = ClipboardContext::new().unwrap();
5	let types = ctx.available_formats().unwrap();
6	println!("{:?}", types);
7
8	let buffer = ctx.get_buffer("public.html").unwrap();
9
10	let string = String::from_utf8(buffer).unwrap();
11
12	println!("{}", string);
13}
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}
Source

pub fn new_with_options(options: ClipboardContextX11Options) -> Result<Self>

Examples found in repository?
examples/image.rs (line 25)
24fn setup_clipboard() -> ClipboardContext {
25	ClipboardContext::new_with_options(ClipboardContextX11Options { read_timeout: None }).unwrap()
26}

Trait Implementations§

Source§

impl Clipboard for ClipboardContext

Source§

fn available_formats(&self) -> Result<Vec<String>>

zh: 获得剪切板当前内容的所有格式 en: Get all formats of the current content in the clipboard
Source§

fn has(&self, format: ContentFormat) -> bool

Source§

fn clear(&self) -> Result<()>

zh: 清空剪切板 en: clear clipboard
Source§

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>

zh: 仅获得无格式纯文本,以字符串形式返回 en: Get plain text content in the clipboard as string
Source§

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>

zh: 获得剪贴板中的html内容,以字符串形式返回 en: Get the html format content in the clipboard as string
Source§

fn get_image(&self) -> Result<RustImageData>

Source§

fn get_files(&self) -> Result<Vec<String>>

Source§

fn get(&self, formats: &[ContentFormat]) -> Result<Vec<ClipboardContent>>

Source§

fn set_buffer(&self, format: &str, buffer: Vec<u8>) -> Result<()>

Source§

fn set_text(&self, text: String) -> Result<()>

Source§

fn set_rich_text(&self, text: String) -> Result<()>

Source§

fn set_html(&self, html: String) -> Result<()>

Source§

fn set_image(&self, image: RustImageData) -> Result<()>

Source§

fn set_files(&self, files: Vec<String>) -> Result<()>

Source§

fn set(&self, contents: Vec<ClipboardContent>) -> Result<()>

set image will clear clipboard

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.