### Get::text basic example Source: https://github.com/1password/arboard Shows how to create a Clipboard, get its text, and print it. Uses the ? operator to propagate errors. ```rust use arboard::Clipboard; fn main() -> Result<(), arboard::Error> { let mut clipboard = Clipboard::new()?; let text = clipboard.get().text()?; println!("{text}"); Ok(()) } ``` -------------------------------- ### Get example Source: https://github.com/1password/arboard Retrieves text and file list from the clipboard. ```rust use arboard::Clipboard; let mut clipboard = Clipboard::new().unwrap(); let text = clipboard.get().text().unwrap(); let paths = clipboard.get().file_list().unwrap(); ``` -------------------------------- ### Get::html example Source: https://github.com/1password/arboard Example of retrieving HTML from the clipboard and handling errors, including the ContentNotAvailable case. ```rust use arboard::Clipboard; let mut ctx = Clipboard::new().unwrap(); match ctx.get().html() { Ok(html) => println!("HTML: {html}"), Err(arboard::Error::ContentNotAvailable) => println!("no HTML on the clipboard"), Err(e) => eprintln!("{e}"), } ``` -------------------------------- ### Example: using Clipboard.set().file_list() Source: https://github.com/1password/arboard Demonstrates setting and getting a file list on the clipboard. The example creates a clipboard, sets the file list to two paths, retrieves it, and asserts equality. ```rust use arboard::Clipboard; fn main() -> Result<(), arboard::Error> { let mut clipboard = Clipboard::new()?; let paths = ["/tmp/a.txt", "/tmp/b.txt"]; clipboard.set().file_list(&paths)?; let roundtrip = clipboard.get().file_list()?; assert_eq!(roundtrip, paths); Ok(()) } ``` -------------------------------- ### Get::image example Source: https://github.com/1password/arboard Example of retrieving an image from the clipboard, asserting the byte length matches RGBA8 dimensions, and printing the size. ```rust use arboard::Clipboard; fn main() -> Result<(), arboard::Error> { let mut clipboard = Clipboard::new()?; let img = clipboard.get().image()?; assert_eq!(img.bytes.len(), img.width * img.height * 4); println!("got a {w}x{h} image", w = img.width, h = img.height); Ok(()) } ``` -------------------------------- ### Example: Retrieve file list from clipboard Source: https://github.com/1password/arboard Example usage of `Get::file_list` to retrieve file paths from the clipboard. Handles the `Error::ContentNotAvailable` case by printing a message. ```rust use arboard::Clipboard; let mut clipboard = Clipboard::new().unwrap(); match clipboard.get().file_list() { Ok(paths) => { for p in &paths { println!("{}", p.display()); } } Err(arboard::Error::ContentNotAvailable) => println!("no files on clipboard"), Err(e) => eprintln!("{e}"), } ``` -------------------------------- ### Clipboard::new example Source: https://github.com/1password/arboard Example usage: creates a Clipboard and retrieves text. Returns Result<(), arboard::Error>. ```rust use arboard::Clipboard; fn main() -> Result<(), arboard::Error> { let mut clipboard = Clipboard::new()?; println!("Clipboard text was: {:?}", clipboard.get_text()); Ok(()) } ``` -------------------------------- ### Get::text error handling example Source: https://github.com/1password/arboard Demonstrates matching on the error variants, specifically checking for ContentNotAvailable when the clipboard is empty or not text. ```rust use arboard::Clipboard; let mut clipboard = Clipboard::new().unwrap(); match clipboard.get().text() { Ok(text) => println!("clipboard contains: {text}"), Err(arboard::Error::ContentNotAvailable) => println!("clipboard is empty or not text"), Err(e) => eprintln!("failed: {e}"), } ``` -------------------------------- ### Set example Source: https://github.com/1password/arboard Sets text in the clipboard. ```rust use arboard::Clipboard; let mut clipboard = Clipboard::new().unwrap(); clipboard.set().text("insert in clipboard").unwrap(); ``` -------------------------------- ### get() method signature Source: https://github.com/1password/arboard Begins a 'get' operation. Returns a `#[must_use]` `Get` builder; choose its terminal method (`text`, `html`, `image`, `file_list`, possibly with `GetExtLinux::clipboard` on Linux). ```rust pub fn get(&mut self) -> Get<'_> ``` -------------------------------- ### Clipboard::get_text example Source: https://github.com/1password/arboard Example usage of get_text handling errors. ```rust use arboard::Clipboard; let mut clipboard = Clipboard::new().unwrap(); match clipboard.get_text() { Ok(text) => println!("got: {text}"), Err(arboard::Error::ContentNotAvailable) => println!("clipboard has no text"), Err(e) => eprintln!("other error: {e}"), } ``` -------------------------------- ### Usage example for to_owned_img Source: https://github.com/1password/arboard Example of using to_owned_img to get an owned ImageData for later use. ```rust use arboard::{Clipboard, ImageData}; let mut clipboard = Clipboard::new().unwrap(); let img = clipboard.get_image().unwrap(); // ImageData<'static> already let owned: ImageData<'static> = img.to_owned_img(); // Pass `owned` to another thread / store it for later use. ``` -------------------------------- ### Clipboard::set_text example Source: https://github.com/1password/arboard Example usage of set_text with &str and String. ```rust use arboard::Clipboard; fn main() -> Result<(), arboard::Error> { let mut clipboard = Clipboard::new()?; clipboard.set_text("Hello, world!")?; // &str clipboard.set_text(String::from("owned string"))?; // String Ok(()) } ``` -------------------------------- ### Basic clipboard usage with arboard Source: https://github.com/1password/arboard/blob/master/README.md Shows how to create a Clipboard instance, get and set text. Uses unwrap() on operations, which will panic if the clipboard is unavailable. Outputs the initial clipboard text and the newly set string. ```rust use arboard::Clipboard; fn main() { let mut clipboard = Clipboard::new().unwrap(); println!("Clipboard text was: {}", clipboard.get_text().unwrap()); let the_string = "Hello, world!"; clipboard.set_text(the_string).unwrap(); println!("But now the clipboard text should be: \"{}\"", the_string); } ``` -------------------------------- ### GetExtLinux usage example Source: https://github.com/1password/arboard Shows how to use GetExtLinux to read from the Primary Linux clipboard selection. Requires the arboard crate. ```rust use arboard::{Clipboard, GetExtLinux, LinuxClipboardKind}; let mut clipboard = Clipboard::new().unwrap(); let primary = clipboard.get().clipboard(LinuxClipboardKind::Primary).text().unwrap(); ``` -------------------------------- ### Usage example for into_owned_bytes Source: https://github.com/1password/arboard Example of using into_owned_bytes to get owned bytes from an image retrieved from the clipboard. ```rust use arboard::Clipboard; let mut clipboard = Clipboard::new().unwrap(); let img = clipboard.get_image().unwrap(); // Other code can now keep the pixels without the clipboard in scope. let owned: std::borrow::Cow<'static, [u8]> = img.into_owned_bytes(); ``` -------------------------------- ### Clipboard::get_image example Source: https://github.com/1password/arboard Example of using get_image to read an image from the clipboard, handling success and error cases such as no image available. ```rust use arboard::Clipboard; let mut ctx = Clipboard::new().unwrap(); match ctx.get_image() { Ok(img) => println!("{}x{} image, {} bytes", img.width, img.height, img.bytes.len()), Err(arboard::Error::ContentNotAvailable) => println!("no image on clipboard"), Err(e) => eprintln!("failed to read image: {e}"), } ``` -------------------------------- ### Clear clipboard example (Rust) Source: https://github.com/1password/arboard Example showing how to clear the clipboard using clear_with().default(). It is safe to clear when already empty. ```rust use arboard::Clipboard; fn main() -> Result<(), arboard::Error> { let mut clipboard = Clipboard::new()?; clipboard.set_text("temporary")?; clipboard.clear_with().default()?; // It is OK to clear when already empty. clipboard.clear_with().default()?; Ok(()) } ``` -------------------------------- ### Complete builder flow (Linux, wait-then-exit) Source: https://github.com/1password/arboard Shows a full example of using the Set builder on Linux: set clipboard text and then sleep briefly. ```rust use arboard::Clipboard; use std::{thread, time::Duration}; fn main() -> Result<(), arboard::Error> { let mut clipboard = Clipboard::new()?; // Block this thread until another app has requested AND received the data. clipboard.set().text("Hello, world!")?; // simple case thread::sleep(Duration::from_millis(50)); Ok(()) } ``` -------------------------------- ### Example: wait with a deadline Source: https://github.com/1password/arboard Sets a deadline of 30 seconds from now. Block until that deadline or until the clipboard contents are replaced, whichever first. Overrides any previously set wait state. ```rust use arboard::{Clipboard, SetExtLinux}; use std::time::{Duration, Instant}; let mut clipboard = Clipboard::new().unwrap(); clipboard .set() .wait_until(Instant::now() + Duration::from_secs(30)) .text("shared value") .unwrap(); ``` -------------------------------- ### Example usage of Clipboard::set_html Source: https://github.com/1password/arboard Creates a clipboard context, sets HTML with alternative text, and sleeps 5 seconds to keep ownership alive on Linux while other apps paste. Requires arboard crate. ```rust use arboard::Clipboard; let mut ctx = Clipboard::new().unwrap(); let html = "

Hello

"; ctx.set_html(html, Some("Hello")).unwrap(); // wait() keeps ownership alive on Linux while other apps paste std::thread::sleep(std::time::Duration::from_secs(5)); ``` -------------------------------- ### Get::text method signature Source: https://github.com/1password/arboard Terminal method that consumes the builder and returns the clipboard contents as UTF-8 text. ```rust pub fn text(self) -> Result ``` -------------------------------- ### Get::file_list signature Source: https://github.com/1password/arboard This is the public method signature for `Get::file_list`. It takes no parameters and returns a `Result, Error>` containing a list of absolute file paths from the clipboard. ```rust pub fn file_list(self) -> Result, Error> ``` -------------------------------- ### Clipboard::set_image example Source: https://github.com/1password/arboard Example of using set_image to write an RGBA8 image to the clipboard. The sample image is 2 pixels wide by 1 pixel high. ```rust use arboard::{Clipboard, ImageData}; let mut ctx = Clipboard::new().unwrap(); let bytes = [ 255, 100, 100, 255, // red pixel 0, 255, 0, 255, // green pixel ]; let img = ImageData { width: 2, height: 1, bytes: bytes.as_ref().into() }; ctx.set_image(img).unwrap(); ``` -------------------------------- ### Get::html signature Source: https://github.com/1password/arboard Function signature for reading HTML from the clipboard. Consumes self and returns a Result. ```rust pub fn html(self) -> Result ``` -------------------------------- ### Example: wait until pasted once Source: https://github.com/1password/arboard Uses set().wait_once() to block until another app requests and receives the clipboard contents. Must be called on an arboard::Clipboard after creating it. Returns after successful paste. ```rust use arboard::{Clipboard, SetExtLinux}; fn main() -> Result<(), Box> { let mut clipboard = Clipboard::new()?; clipboard.set().wait_once().text("Hello, world!")?; // Returns only after another app has requested AND received the contents. Ok(()) } ``` -------------------------------- ### Complete builder flow Source: https://github.com/1password/arboard Demonstrates the complete builder flow for retrieving clipboard content, including Linux-specific clipboard selection. ```APIDOC ## Complete builder flow ### Description Demonstrates the complete builder flow for retrieving clipboard content, including Linux-specific clipboard selection. ### Method Rust code example ### Endpoint N/A ### Parameters N/A ### Response N/A ### Request Example ```rust use arboard::{Clipboard, GetExtLinux, LinuxClipboardKind}; fn main() -> Result<(), arboard::Error> { let mut clipboard = Clipboard::new()?; // Linux only: read from the PRIMARY selection (middle-click paste). #[cfg(all(unix, not(any(target_os = "macos", target_os = "android", target_os = "emscripten"))))] let text = clipboard.get().clipboard(LinuxClipboardKind::Primary).text()?; Ok(()) } ``` ``` -------------------------------- ### Clear example Source: https://github.com/1password/arboard Clears the clipboard after setting text, then verifies that the clipboard is empty or returns `ContentNotAvailable`. ```rust use arboard::Clipboard; let mut ctx = Clipboard::new().unwrap(); ctx.set_text("secret").unwrap(); ctx.clear().unwrap(); assert!(matches!( ctx.get_text(), Err(arboard::Error::ContentNotAvailable) | Ok(ref s) if s.is_empty() )); ``` -------------------------------- ### Complete builder flow with Linux PRIMARY selection Source: https://github.com/1password/arboard Shows a complete builder flow using `GetExtLinux` and `LinuxClipboardKind::Primary` to read text from the primary selection on Linux. The `#[cfg]` attribute restricts this to Unix-like systems excluding macOS, Android, and Emscripten. ```rust use arboard::{Clipboard, GetExtLinux, LinuxClipboardKind}; fn main() -> Result<(), arboard::Error> { let mut clipboard = Clipboard::new()?; // Linux only: read from the PRIMARY selection (middle-click paste). #[cfg(all(unix, not(any(target_os = "macos", target_os = "android", target_os = "emscripten"))))] let text = clipboard.get().clipboard(LinuxClipboardKind::Primary).text()?; Ok(()) } ``` -------------------------------- ### Get<'clipboard> struct definition Source: https://github.com/1password/arboard Defines the builder struct that gets a value from the clipboard. It is marked #[must_use] and holds a platform-specific Get instance. ```rust #[must_use] pub struct Get<'clipboard> { pub(crate) platform: platform::Get<'clipboard>, } ``` -------------------------------- ### ClearExtLinux usage example Source: https://github.com/1password/arboard Shows how to use ClearExtLinux to clear the Secondary Linux clipboard selection. Uses the ? operator on the Result, so the calling function must return a compatible error type. ```rust use arboard::{Clipboard, ClearExtLinux, LinuxClipboardKind}; let mut clipboard = Clipboard::new().unwrap(); clipboard .clear_with() .clipboard(LinuxClipboardKind::Secondary)?; ``` -------------------------------- ### Clipboard::get Source: https://github.com/1password/arboard Begins a "get" operation. Returns a `#[must_use]` [Get](get.md) builder; choose its terminal method (`text`, `html`, `image`, `file_list`, possibly with `GetExtLinux::clipboard` on Linux). ```APIDOC ## `Clipboard::get` ### Description Begins a "get" operation. Returns a `#[must_use]` [Get](get.md) builder; choose its terminal method (`text`, `html`, `image`, `file_list`, possibly with `GetExtLinux::clipboard` on Linux). ### Method `get` ### Signature ```rust pub fn get(&mut self) -> Get<'_> ``` ### Example ```rust use arboard::Clipboard; let mut clipboard = Clipboard::new().unwrap(); let text = clipboard.get().text().unwrap(); let paths = clipboard.get().file_list().unwrap(); ``` ``` -------------------------------- ### Example: exclude_from_history usage Source: https://github.com/1password/arboard Shows how to use SetExtWindows to exclude clipboard data from the system clipboard history. Requires importing SetExtWindows and chaining the method before the terminal text operation. ```rust use arboard::{Clipboard, SetExtWindows}; fn main() -> Result<(), arboard::Error> { let mut clipboard = Clipboard::new()?; clipboard .set() .exclude_from_history() .text("session token")?; Ok(()) } ``` -------------------------------- ### Get::html Source: https://github.com/1password/arboard Retrieves the HTML content from the clipboard. Returns a Result with the HTML string or an error if no HTML content is available. ```APIDOC ## Get::html ### Description Retrieves the HTML content from the clipboard. Returns a Result with the HTML string or an error if no HTML content is available. ### Method `pub fn html(self) -> Result` ### Parameters None — consumes `self`. ### Return `Result` — the HTML contents of the selected clipboard. ### Errors | Error | Condition | |-------|-----------| | `Error::ContentNotAvailable` | No HTML content (X11: no `text/html` target offered by owner; Wayland: `ClipboardEmpty`/`NoMimeType`; macOS: no `NSPasteboardTypeHTML` item). | | `Error::ConversionFailure` | Bytes are not valid UTF-8. | | `Error::Unknown { description }` | Windows: could not register/read the "HTML Format" clipboard format. | ### Platform notes - macOS: reads `NSPasteboardTypeHTML`; because HTML written by `set_html` is wrapped (charset meta + `…` suffix), the returned string ends with the wrapper — exact round-trip equality with the input is **not** guaranteed on macOS (the test suite asserts `content.ends_with(&format!("{html}"))`). - Windows: reads the registered "HTML Format" clipboard format (the `wrap_html` envelope, `src/platform/windows.rs`). - Linux: reads `text/html` verbatim. ### Request Example ```rust use arboard::Clipboard; let mut ctx = Clipboard::new().unwrap(); match ctx.get().html() { Ok(html) => println!("HTML: {html}"), Err(arboard::Error::ContentNotAvailable) => println!("no HTML on the clipboard"), Err(e) => eprintln!("{e}"), } ``` ``` -------------------------------- ### Clear Linux clipboard selection example (Rust) Source: https://github.com/1password/arboard Uses ClearExtLinux::clipboard(LinuxClipboardKind) to target a specific selection, here Secondary, instead of the default Clipboard on Linux. ```rust use arboard::{Clipboard, LinuxClipboardKind, ClearExtLinux}; fn main() -> Result<(), arboard::Error> { let mut clipboard = Clipboard::new()?; clipboard .clear_with() .clipboard(LinuxClipboardKind::Secondary)?; Ok(()) } ``` -------------------------------- ### GetExtLinux::clipboard Source: https://github.com/1password/arboard Sets the clipboard selection that the get operation will retrieve data from. On Wayland, attempting to use the Secondary clipboard will return an error. ```APIDOC ## GetExtLinux::clipboard ### Description Sets the clipboard the operation will retrieve data from. If wayland support is enabled and available, attempting to use the Secondary clipboard will return an error. ### Method clipboard ### Signature ```rust fn clipboard(self, selection: LinuxClipboardKind) -> Self; ``` ### Parameters - **selection** (LinuxClipboardKind) - Required - The clipboard selection to read from. ### Example ```rust use arboard::{Clipboard, GetExtLinux, LinuxClipboardKind}; let mut clipboard = Clipboard::new().unwrap(); let primary = clipboard.get().clipboard(LinuxClipboardKind::Primary).text().unwrap(); ``` ``` -------------------------------- ### Get::file_list Source: https://github.com/1password/arboard Retrieves a list of absolute file paths from the clipboard. Returns an error if no file-list content is available or if conversion fails. ```APIDOC ## `Get::file_list` ### Description Retrieves a list of absolute file paths from the clipboard. Returns an error if no file-list content is available or if conversion fails. ### Method Rust method call ### Endpoint `pub fn file_list(self) -> Result, Error>` ### Parameters None — consumes `self`. ### Return `Result, Error>` — a list of absolute file paths from the clipboard. ### Errors | Error | Condition | |-------|-----------| | `Error::ContentNotAvailable` | No file-list content (X11: neither `text/uri-list` nor `x-special/gnome-copied-files`; macOS: `readObjectsForClasses:options:` returned no URLs; Windows: `get_file_list_path` failed). | | `Error::ConversionFailure` | X11/Wayland: no files could be canonicalized to URIs when the list was *written* by another party — reading itself converts URIs leniently. | ### Platform notes - Linux: decodes `file://` URIs with percent-decoding from either `text/uri-list` or GNOME's `x-special/gnome-copied-files` (action header `copy\n`/`cut\n` is ignored). Linux does **not** expose whether files were marked copy vs cut. - macOS: reads `NSURL` file URLs (`NSPasteboardURLReadingFileURLsOnlyKey`). - Windows: reads the `CF_HDROP` format. ### Request Example ```rust use arboard::Clipboard; let mut clipboard = Clipboard::new().unwrap(); match clipboard.get().file_list() { Ok(paths) => { for p in &paths { println!("{}", p.display()); } } Err(arboard::Error::ContentNotAvailable) => println!("no files on clipboard"), Err(e) => eprintln!("{e}"), } ``` ``` -------------------------------- ### Get::text Source: https://github.com/1password/arboard Retrieves the text contents from the clipboard. This method consumes the builder and returns the clipboard's text as a UTF-8 string, or an error if the clipboard is empty or contains non-text data. ```APIDOC ## Get::text ### Description Retrieves the text contents from the clipboard. This method consumes the builder and returns the clipboard's text as a UTF-8 string, or an error if the clipboard is empty or contains non-text data. ### Method `pub fn text(self) -> Result` ### Parameters None — consumes `self`. ### Return `Result` — the UTF-8 text contents of the selected clipboard. ### Errors | Error | Condition | |-------|-----------| | `Error::ContentNotAvailable` | Clipboard empty, contents are not text, or (Windows) no `CF_UNICODETEXT` format available. | | `Error::ConversionFailure` | Raw bytes are not valid UTF-8 (Windows: buffer conversion). | | `Error::ClipboardOccupied` | Windows: could not open the clipboard after 5 attempts. | ### Request Example ```rust use arboard::Clipboard; fn main() -> Result<(), arboard::Error> { let mut clipboard = Clipboard::new()?; let text = clipboard.get().text()?; println!("{text}"); Ok(()) } ``` ### Error handling example ```rust use arboard::Clipboard; let mut clipboard = Clipboard::new().unwrap(); match clipboard.get().text() { Ok(text) => println!("clipboard contains: {text}"), Err(arboard::Error::ContentNotAvailable) => println!("clipboard is empty or not text"), Err(e) => eprintln!("failed: {e}"), } ``` ``` -------------------------------- ### chained with file_list Source: https://github.com/1password/arboard Example usage combining exclude_from_history with the file_list terminal operation. Note use of unwrap for error handling. ```rust use arboard::{Clipboard, SetExtApple}; let mut clipboard = Clipboard::new().unwrap(); clipboard .set() .exclude_from_history() .file_list(&["/tmp/secret.txt"]) .unwrap(); ``` -------------------------------- ### Clipboard::get() Source: https://github.com/1password/arboard Returns a Get builder object for retrieving clipboard contents. The builder is consumed by terminal methods such as text, html, image, and file_list. ```APIDOC ## Clipboard::get() ### Description Returns a Get builder object for retrieving clipboard contents. The builder is consumed by terminal methods such as text, html, image, and file_list. ### Method Builder method ### Signature `Clipboard::get(&self) -> Get<'_>` ### Availability All platforms ### Returns - `Get<'_>` - A builder for clipboard retrieval operations ``` -------------------------------- ### Example: history exclusion Source: https://github.com/1password/arboard Signals clipboard managers not to keep the data in history via the x-kde-passwordManagerHint MIME on supported managers. Must be chained before the terminal text method. ```rust use arboard::{Clipboard, SetExtLinux}; let mut clipboard = Clipboard::new().unwrap(); clipboard.set().exclude_from_history().text("hunter2").unwrap(); ``` -------------------------------- ### Set::html example Source: https://github.com/1password/arboard Sets HTML content on the clipboard with optional plain-text alternative. On Windows, alt_text is written as CF_UNICODETEXT and the HTML is wrapped with the wrap_html CF_HTML envelope. On macOS, uses setString_forType for NSPasteboardTypeHTML and NSPasteboardTypeString. On Linux, stores both MIME types in one selection. ```rust use arboard::Clipboard; let mut clipboard = Clipboard::new().unwrap(); clipboard .set() .html("hello world!", Some("hello world!")) .unwrap(); ``` -------------------------------- ### composability with html Source: https://github.com/1password/arboard Example usage combining exclude_from_history with the html terminal operation. The method is infallible; errors surface from the terminal method. ```rust use arboard::{Clipboard, SetExtApple}; let mut clipboard = Clipboard::new().unwrap(); clipboard .set() .exclude_from_history() .html("secret", Some("secret")) .unwrap(); ``` -------------------------------- ### Get::image signature Source: https://github.com/1password/arboard Feature-gated signature for reading an image from the clipboard. Only available with the image-data feature (enabled by default). Consumes self. ```rust #[cfg(feature = "image-data")] pub fn image(self) -> Result, Error> ``` -------------------------------- ### Set::image example Source: https://github.com/1password/arboard Sets an RGBA8 image on the clipboard. Available with the image-data feature (enabled by default). On macOS, builds an NSImage via CGImageCreate. On Linux, stores PNG under the atom image/png. On Windows, registers PNG format first, then CF_DIBV5. ```rust use arboard::{Clipboard, ImageData}; let mut clipboard = Clipboard::new().unwrap(); let img = ImageData { width: 2, height: 2, bytes: vec![255, 100, 100, 255, 100, 255, 100, 100, 100, 100, 255, 100, 0, 0, 0, 255].into(), }; clipboard.set().image(img).unwrap(); ``` -------------------------------- ### Builder structs: Get, Set, Clear Source: https://github.com/1password/arboard Public builder structs returned by Clipboard::get(), set(), and clear_with(). They expose terminal methods for clipboard operations. ```APIDOC ## Builder structs: Get, Set, Clear ### Description Public builder structs returned by Clipboard::get(), set(), and clear_with(). They expose terminal methods for clipboard operations. ### Structs - `Get<'clipboard>` - Returned by `Clipboard::get()`. - `Set<'clipboard>` - Returned by `Clipboard::set()`. - `Clear<'clipboard>` - Returned by `Clipboard::clear_with()`. ### Notes - All are `#[must_use]`. - Fields are `pub(crate)`. - They are the `Self` types of the sealed extension traits. ``` -------------------------------- ### exclude_from_history with text Source: https://github.com/1password/arboard Example usage: set clipboard text with exclusions from history. The method consumes and returns Self, call it before the terminal operation. ```rust use arboard::{Clipboard, SetExtApple}; fn main() -> Result<(), arboard::Error> { let mut clipboard = Clipboard::new()?; clipboard .set() .exclude_from_history() .text("password manager data")?; Ok(()) } ``` -------------------------------- ### Get::image Source: https://github.com/1password/arboard Retrieves an image from the clipboard as decoded RGBA8 pixels. Only available with the `image-data` feature (enabled by default). ```APIDOC ## Get::image ### Description Retrieves an image from the clipboard as decoded RGBA8 pixels. Only available with the `image-data` feature (enabled by default). ### Method `#[cfg(feature = "image-data")] pub fn image(self) -> Result, Error>` ### Parameters None — consumes `self`. ### Return `Result, Error>` — decoded RGBA8 pixels. The `'static` lifetime means the returned pixel buffer is always owned. ### Errors | Error | Condition | |-------|-----------| | `Error::ContentNotAvailable` | Clipboard is empty / not an image / unsupported image format. | | `Error::ConversionFailure` | Native image data could not be decoded to RGBA8 (e.g. TIFF on macOS, PNG/DIBV5 on Windows, PNG on Linux). | | `Error::Unknown { description }` | Windows: failed reading PNG/DIBV5 data; DIBV5 data shorter than a `BITMAPV5HEADER`. | ### Request Example ```rust use arboard::Clipboard; fn main() -> Result<(), arboard::Error> { let mut clipboard = Clipboard::new()?; let img = clipboard.get().image()?; assert_eq!(img.bytes.len(), img.width * img.height * 4); println!("got a {w}x{h} image", w = img.width, h = img.height); Ok(()) } ``` ``` -------------------------------- ### set() method signature Source: https://github.com/1password/arboard Begins a 'set' operation. Returns a `#[must_use]` `Set` builder; choose its terminal method (`text`, `html`, `image`, `file_list`, possibly with `SetExtLinux`/`SetExtWindows`/`SetExtApple` options). ```rust pub fn set(&mut self) -> Set<'_> ``` -------------------------------- ### Clipboard::new Source: https://github.com/1password/arboard Creates a new Clipboard instance, providing a handle to the platform clipboard. This is the entry point for accessing clipboard functionality. ```APIDOC ## `Clipboard::new` ### Description Creates a new `Clipboard` instance, providing a handle to the platform clipboard. This is the entry point for accessing clipboard functionality. ### Method `Clipboard::new` ### Parameters None. ### Return `Result` — a handle to the platform clipboard. ### Errors | Error | Condition | |-------|-----------| | `Error::ClipboardNotSupported` | macOS: `NSPasteboard::generalPasteboard` returned NULL (e.g. running as a daemon under launchd). Linux: X11 connection could not be established / Wayland compositor unreachable. | | `Error::Unknown { description }` | Linux X11: server connection timed out ("X11 server connection timed out because it was unreachable") or no screen found. Linux Wayland: `wl-clipboard-rs` reported an error while probing the compositor. | May be retried if clipboard access is temporarily unavailable. ### Request Example ```rust use arboard::Clipboard; fn main() -> Result<(), arboard::Error> { let mut clipboard = Clipboard::new()?; println!("Clipboard text was: {:?}", clipboard.get_text()); Ok(()) } ``` ``` -------------------------------- ### Clipboard::clear_with Source: https://github.com/1password/arboard Begins a "clear" operation for further configuration (Linux only, via `ClearExtLinux::clipboard`). See [Clear](clear.md). ```APIDOC ## `Clipboard::clear_with` ### Description Begins a "clear" operation for further configuration (Linux only, via `ClearExtLinux::clipboard`). See [Clear](clear.md). ### Method `clear_with` ### Signature ```rust pub fn clear_with(&mut self) -> Clear<'_> ``` ``` -------------------------------- ### ImageData<'a> Source: https://github.com/1password/arboard Represents an image with width, height, and RGBA8 pixel data. It is used with the Clipboard, Set, and Get APIs for image operations. ```APIDOC ## ImageData<'a> ### Description Represents an image with width, height, and RGBA8 pixel data. It is used with the Clipboard, Set, and Get APIs for image operations. ### Fields - **width** (`usize`) - Required - Width in pixels. - **height** (`usize`) - Required - Height in pixels. - **bytes** (`Cow<'a, [u8]>`) - Required - RGBA8 pixel data, row-major; `width * height * 4` bytes. ### Methods - `into_owned_bytes(self) -> Cow<'static, [u8]>` - `to_owned_img(&self) -> ImageData<'static>` ### Accepted/Returned by - `Clipboard::set_image(image: ImageData) -> Result<(), Error>` - `Clipboard::get_image() -> Result, Error>` - `Set::image(image: ImageData) -> Result<(), Error>` - `Get::image() -> Result, Error>` ``` -------------------------------- ### Handle empty clipboard reads after clear Source: https://github.com/1password/arboard After `Clipboard::clear()`, `get_text()` may return `Ok("")` or `Err(ContentNotAvailable)` depending on platform. This pattern accepts both outcomes, as used in the crate's own tests (`src/lib.rs`). ```rust match ctx.get_text() { Ok(text) => assert!(text.is_empty()), Err(Error::ContentNotAvailable) => {} Err(e) => panic!("unexpected error: {e}"), }; ``` -------------------------------- ### Setting primary clipboard text Source: https://github.com/1password/arboard Shows how to set the primary clipboard (middle-click selection) using the Linux extension API. Requires the SetExtLinux trait. ```rust use arboard::{Clipboard, LinuxClipboardKind, SetExtLinux}; let mut clipboard = Clipboard::new().unwrap(); clipboard.set().clipboard(LinuxClipboardKind::Primary).text("middle-click me".to_owned()).unwrap(); ``` -------------------------------- ### Clipboard::new signature Source: https://github.com/1password/arboard Creates a new Clipboard handle. Errors include ClipboardNotSupported when the platform clipboard is unavailable, or Unknown on Linux connection issues. ```rust pub fn new() -> Result ``` -------------------------------- ### SetExtLinux::wait_once Source: https://github.com/1password/arboard Blocks until the clipboard contents have been served to another app once. This is a superset of wait() and overrides any previously set wait state. ```APIDOC ## SetExtLinux::wait_once ### Description Block until the clipboard contents have been *served to another app once*. Superset of `wait()` — overrides any previously set wait state. ### Method `fn wait_once(self) -> Self` ### Parameters - `self` - Required - The Set builder instance ### Returns `Self` - The Set builder for chaining ### Example ```rust use arboard::{Clipboard, SetExtLinux}; fn main() -> Result<(), Box> { let mut clipboard = Clipboard::new()?; clipboard.set().wait_once().text("Hello, world!")?; // Returns only after another app has requested AND received the contents. Ok(()) } ``` ``` -------------------------------- ### Set::text method signature Source: https://github.com/1password/arboard Defines the text method that accepts any UTF-8 string and returns a Result. Returns () on success. ```rust pub fn text<'a, T: Into>>(self, text: T) -> Result<(), Error> ``` -------------------------------- ### clear_with() method signature Source: https://github.com/1password/arboard Begins a 'clear' operation for further configuration (Linux only, via `ClearExtLinux::clipboard`). See `Clear`. ```rust pub fn clear_with(&mut self) -> Clear<'_> ``` -------------------------------- ### Clipboard::new() Source: https://github.com/1password/arboard Creates a new Clipboard handle that manages access to the OS clipboard. The handle holds or lazily acquires native clipboard resources depending on the platform. ```APIDOC ## Clipboard::new() ### Description Creates a new Clipboard handle that manages access to the OS clipboard. The handle holds or lazily acquires native clipboard resources depending on the platform. ### Method Constructor ### Signature `Clipboard::new() -> Result` ### Availability All platforms ### Returns - `Result` - A new Clipboard instance on success, or an Error on failure ``` -------------------------------- ### WaitConfig enum definition Source: https://github.com/1password/arboard Defines the wait state for the Set builder on Linux. It includes Until, Once, Forever, and None variants, with None as the default. ```rust #[derive(Default)] pub(crate) enum WaitConfig { /// Waits until the given [`Instant`] has reached. Until(Instant), /// Waits until the clipboard contents have been retrieved once. Once, /// Waits forever until a new event is reached. Forever, /// It shouldn't wait. #[default] None, } ``` -------------------------------- ### Set::file_list signature Source: https://github.com/1password/arboard Defines the public method signature for setting a list of file paths on the clipboard. Accepts a slice of types implementing AsRef and returns Result<(), Error>. ```rust pub fn file_list(self, file_list: &[impl AsRef]) -> Result<(), Error> ``` -------------------------------- ### Set::file_list Source: https://github.com/1password/arboard Places a list of file paths onto the system clipboard. The paths are converted to platform-specific formats (URI list on Linux, NSURLs on macOS, CF_HDROP on Windows) and written to the clipboard. ```APIDOC ## Set::file_list ### Description Places a list of file paths onto the system clipboard. The paths are converted to platform-specific formats (URI list on Linux, NSURLs on macOS, CF_HDROP on Windows) and written to the clipboard. ### Method Rust function call ### Endpoint `pub fn file_list(self, file_list: &[impl AsRef]) -> Result<(), Error>` ### Parameters #### Parameters - **`file_list`** (`&[impl AsRef]`) - Required - File paths (relative or absolute) to place on the clipboard. ### Return `Result<(), Error>` — `()` on success. ### Errors | Error | Condition | |-------|-----------| | `Error::ConversionFailure` | No path could be canonicalized (X11/Wayland: `paths_to_uri_list` returns none; macOS: URI list empty; Windows: all `to_final_path_wide` calls failed). | | `Error::Unknown { description }` | Native write failure. | | `Error::ClipboardOccupied` | Windows: clipboard open failed. | ### Platform behavior - Linux: writes `text/uri-list` (`file://` URIs, percent-encoded, CRLF-separated per RFC 2045 §2.10) **and** `x-special/gnome-copied-files` with a `copy` action header — files are marked for copying on Linux. - macOS: canonicalized paths become `NSURL` objects written to the pasteboard. - Windows: paths are resolved via `GetFinalPathNameByHandleW` (opening the file with `FILE_FLAG_BACKUP_SEMANTICS`, no permissions) and written as a `CF_HDROP` block (`DROPFILES` header + wide strings, `src/platform/windows.rs` `Set::file_list`). ### Request Example ```rust use arboard::Clipboard; fn main() -> Result<(), arboard::Error> { let mut clipboard = Clipboard::new()?; let paths = ["/tmp/a.txt", "/tmp/b.txt"]; clipboard.set().file_list(&paths)?; let roundtrip = clipboard.get().file_list()?; assert_eq!(roundtrip, paths); Ok(()) } ``` ``` -------------------------------- ### SetExtLinux::clipboard Source: https://github.com/1password/arboard Chooses which Linux clipboard selection to write to. ```APIDOC ## SetExtLinux::clipboard ### Description Choose which selection to write to. ### Method `fn clipboard(self, selection: LinuxClipboardKind) -> Self` ### Parameters - `self` - Required - The Set builder instance - `selection` (LinuxClipboardKind) - Required - The clipboard selection to write to ### Returns `Self` - The Set builder for chaining ``` -------------------------------- ### SetExtLinux::wait_until Source: https://github.com/1password/arboard Blocks until the specified deadline is reached or the clipboard contents are replaced, whichever comes first. This is a superset of wait() and overrides any previously set wait state. ```APIDOC ## SetExtLinux::wait_until ### Description Block until `deadline` (an `std::time::Instant`) is reached or the contents are replaced, whichever first. Superset of `wait()` — overrides any previously set wait state. ### Method `fn wait_until(self, deadline: Instant) -> Self` ### Parameters - `self` - Required - The Set builder instance - `deadline` (Instant) - Required - The time until which to block ### Returns `Self` - The Set builder for chaining ### Example ```rust use arboard::{Clipboard, SetExtLinux}; use std::time::{Duration, Instant}; let mut clipboard = Clipboard::new().unwrap(); clipboard .set() .wait_until(Instant::now() + Duration::from_secs(30)) .text("shared value") .unwrap(); ``` ``` -------------------------------- ### Clipboard::set Source: https://github.com/1password/arboard Begins a "set" operation. Returns a `#[must_use]` [Set](set.md) builder; choose its terminal method (`text`, `html`, `image`, `file_list`, possibly with `SetExtLinux`/`SetExtWindows`/`SetExtApple` options). ```APIDOC ## `Clipboard::set` ### Description Begins a "set" operation. Returns a `#[must_use]` [Set](set.md) builder; choose its terminal method (`text`, `html`, `image`, `file_list`, possibly with `SetExtLinux`/`SetExtWindows`/`SetExtApple` options). ### Method `set` ### Signature ```rust pub fn set(&mut self) -> Set<'_> ``` ### Example ```rust use arboard::Clipboard; let mut clipboard = Clipboard::new().unwrap(); clipboard.set().text("insert in clipboard").unwrap(); ``` ``` -------------------------------- ### clear() method signature Source: https://github.com/1password/arboard Clears any contents from the platform's default clipboard, regardless of format. Equivalent to `self.clear_with().default()`. ```rust pub fn clear(&mut self) -> Result<(), Error> ``` -------------------------------- ### Function signature for Clipboard::set_html Source: https://github.com/1password/arboard Signature for setting HTML content on the clipboard with optional alternative text. Requires html and an optional alt_text parameter. Returns Result<(), Error>. ```rust pub fn set_html<'a, T: Into>>( &mut self, html: T, alt_text: Option, ) -> Result<(), Error> ``` -------------------------------- ### LinuxClipboardKind enum Source: https://github.com/1password/arboard Defines the clipboard kinds available on Linux: Clipboard, Primary, and Secondary, with Wayland and X11 caveats. ```rust #[derive(Copy, Clone, Debug)] pub enum LinuxClipboardKind { /// Typically used selection for explicit cut/copy/paste actions (ie. windows/macos like /// clipboard behavior) Clipboard, /// Typically used for mouse selections and/or currently selected text. Accessible via middle /// mouse click. /// /// *On Wayland, this may not be available for all systems (requires a compositor supporting /// version 2 or above) and operations using this will return an error if unsupported.* Primary, /// The secondary clipboard is rarely used but theoretically available on X11. /// /// *On Wayland, this is not be available and operations using this variant will return an /// error.* Secondary, } ``` -------------------------------- ### SetExtLinux::wait Source: https://github.com/1password/arboard Blocks after writing until the clipboard contents are replaced by another owner. Blocks forever until overwritten. ```APIDOC ## SetExtLinux::wait ### Description Block after writing until the clipboard contents are replaced by another owner. Blocks forever until overwritten. ### Method `fn wait(self) -> Self` ### Parameters - `self` - Required - The Set builder instance ### Returns `Self` - The Set builder for chaining ### Example ```rust use arboard::{Clipboard, SetExtLinux}; let mut clipboard = Clipboard::new().unwrap(); clipboard.set().wait().text("Hello, world!").unwrap(); ``` ``` -------------------------------- ### SetExtLinux Trait Definition Source: https://github.com/1password/arboard Sealed trait for arboard's Set builder on Linux. Adds Linux-specific clipboard operations: wait, wait_until, wait_once, clipboard, and exclude_from_history. All methods consume self and return Self for chaining, usable only on arboard's Set type. ```rust pub trait SetExtLinux: private::Sealed { fn wait(self) -> Self; fn wait_until(self, deadline: Instant) -> Self; fn wait_once(self) -> Self; fn clipboard(self, selection: LinuxClipboardKind) -> Self; fn exclude_from_history(self) -> Self; } ``` -------------------------------- ### Clipboard::set() Source: https://github.com/1password/arboard Returns a Set builder object for setting clipboard contents. The builder is consumed by terminal methods such as text, html, image, and file_list. ```APIDOC ## Clipboard::set() ### Description Returns a Set builder object for setting clipboard contents. The builder is consumed by terminal methods such as text, html, image, and file_list. ### Method Builder method ### Signature `Clipboard::set(&self) -> Set<'_>` ### Availability All platforms ### Returns - `Set<'_>` - A builder for clipboard set operations ``` -------------------------------- ### GetExtLinux trait definition Source: https://github.com/1password/arboard Defines the GetExtLinux trait with a clipboard method that sets the selection for clipboard retrieval. Attempting to use the Secondary clipboard with Wayland support enabled and available returns an error. ```rust pub trait GetExtLinux: private::Sealed { /// Sets the clipboard the operation will retrieve data from. /// /// If wayland support is enabled and available, attempting to use the Secondary clipboard will /// return an error. fn clipboard(self, selection: LinuxClipboardKind) -> Self; } ```