From 963d607a1f850b8e5c1f356041122163c3169b29 Mon Sep 17 00:00:00 2001 From: Vitor Ayres Date: Mon, 6 Nov 2023 09:11:28 -0300 Subject: [PATCH] feat: clipboard rust guide #1475 (#1622) * create rust guide * update invoke import * simplify rust guide * simplify even more to match it to JS --- src/content/docs/features/clipboard.mdx | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/content/docs/features/clipboard.mdx b/src/content/docs/features/clipboard.mdx index 8b29a3b1ed..7d568a0c79 100644 --- a/src/content/docs/features/clipboard.mdx +++ b/src/content/docs/features/clipboard.mdx @@ -41,6 +41,8 @@ Install the clipboard plugin to get started. } ``` + + @@ -84,10 +86,10 @@ The clipboard plugin is available in both JavaScript and Rust. ```js import { writeText, readText } from '@tauri-apps/plugin-clipboard-manager'; -// Write text to the clipboard +// Write content to clipboard await writeText('Tauri is awesome!'); -// Read text from the clipboard +// Read content from clipboard const content = await readText(); console.log(content); // Prints "Tauri is awesome!" to the console @@ -96,9 +98,23 @@ console.log(content); -{/* TODO: */} +```rust +use tauri_plugin_clipboard_manager::ClipboardExt; + +// Write content to clipboard +let clipboard_content = tauri_plugin_clipboard_manager::ClipKind::PlainText { + label: Some("Label".to_string()), + text: "Tauri is awesome!".to_string(), +}; +app.clipboard().write(clipboard_content).unwrap(); - +// Read content from clipboard +let content = app.clipboard().read(); +println!("{:?}", content.unwrap()); +// Prints "Tauri is awesome!" to the terminal + + +```