Trait ClipboardProvider

Source
pub trait ClipboardProvider {
    // Required methods
    fn read_text(&self) -> Option<String>;
    fn write_text(&self, text: &str) -> Result<(), String>;
}
Expand description

Provider-neutral UTF-8 clipboard access.

Implementations may bridge a platform clipboard or use MemoryClipboard for deterministic/headless work. The trait is UI-thread-local (Send and Sync are not required). None means text is unavailable, which is distinct from Some(""); write errors are provider-defined displayable strings.

§Examples

use ailloli_ui_runtime::app::{ClipboardProvider, MemoryClipboard};
let clipboard = MemoryClipboard::new();
clipboard.write_text("copied")?;
assert_eq!(clipboard.read_text().as_deref(), Some("copied"));

Required Methods§

Source

fn read_text(&self) -> Option<String>

Reads current UTF-8 text, or None when no text can be supplied.

§Examples
use ailloli_ui_runtime::app::{ClipboardProvider, MemoryClipboard};
assert_eq!(MemoryClipboard::new().read_text(), Some(String::new()));
Source

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

Replaces clipboard text or returns a provider-defined failure message.

Empty text is a valid value and is not equivalent to clearing provider availability.

§Errors

Returns a provider-defined display string when the backend rejects or cannot complete the write.

§Examples
use ailloli_ui_runtime::app::{ClipboardProvider, MemoryClipboard};
let clipboard = MemoryClipboard::new();
clipboard.write_text("")?;
assert_eq!(clipboard.read_text().as_deref(), Some(""));

Implementors§

Source§

impl ClipboardProvider for MemoryClipboard

Provides infallible, UI-thread-local text storage.