Introduce write method to Clipboard trait

This commit is contained in:
Héctor Ramón Jiménez 2021-03-10 01:18:22 +01:00
parent b22b0dd7ff
commit 35425001ed
2 changed files with 10 additions and 0 deletions

View File

@ -3,4 +3,7 @@
pub trait Clipboard { pub trait Clipboard {
/// Reads the current content of the [`Clipboard`] as text. /// Reads the current content of the [`Clipboard`] as text.
fn read(&self) -> Option<String>; fn read(&self) -> Option<String>;
/// Writes the given text contents to the [`Clipboard`].
fn write(&mut self, contents: String);
} }

View File

@ -16,4 +16,11 @@ impl iced_native::Clipboard for Clipboard {
fn read(&self) -> Option<String> { fn read(&self) -> Option<String> {
self.0.read().ok() self.0.read().ok()
} }
fn write(&mut self, contents: String) {
match self.0.write(contents) {
Ok(()) => {}
Err(error) => log::warn!("error writing to clipboard: {}", error),
}
}
} }