pub trait Clipboard {
// Required methods
fn get_text(&mut self) -> Result<String, ClipboardError>;
fn set_text(&mut self, text: String) -> Result<(), ClipboardError>;
}Expand description
Read/write access to a text clipboard.
A trait rather than a single concrete type so callers can substitute a fake for testing – see this module’s doc comment.
§Examples
use retroglyph_window::clipboard::{Clipboard, ClipboardError};
#[derive(Default)]
struct FakeClipboard {
contents: Option<String>,
}
impl Clipboard for FakeClipboard {
fn get_text(&mut self) -> Result<String, ClipboardError> {
self.contents
.clone()
.ok_or_else(|| ClipboardError::new("clipboard is empty"))
}
fn set_text(&mut self, text: String) -> Result<(), ClipboardError> {
self.contents = Some(text);
Ok(())
}
}
let mut clip = FakeClipboard::default();
clip.set_text("hello".to_string())?;
assert_eq!(clip.get_text()?, "hello");Required Methods§
Sourcefn get_text(&mut self) -> Result<String, ClipboardError>
fn get_text(&mut self) -> Result<String, ClipboardError>
Returns the current clipboard contents as text.
§Errors
Returns ClipboardError if the clipboard is unavailable, or does not currently hold
text (e.g. it holds an image, or is empty).
Sourcefn set_text(&mut self, text: String) -> Result<(), ClipboardError>
fn set_text(&mut self, text: String) -> Result<(), ClipboardError>
Replaces the clipboard contents with text.
§Errors
Returns ClipboardError if the clipboard is unavailable.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl Clipboard for SystemClipboard
Available on non-WebAssembly only.