pub struct ClipboardContext { /* private fields */ }

Implementations§

source§

impl ClipboardContext

source

pub fn new() -> Result<Self>

Examples found in repository?
examples/buffer.rs (line 4)
3
4
5
6
7
8
9
10
11
12
13
fn main() {
    let ctx = ClipboardContext::new().unwrap();
    let types = ctx.available_formats().unwrap();
    println!("{:?}", types);

    let buffer = ctx.get_buffer("public.html").unwrap();

    let string = String::from_utf8(buffer).unwrap();

    println!("{}", string);
}
More examples
Hide additional 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

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 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<()>

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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

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>,

§

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.