Expose `read` and `write` methods in `iced_winit::Clipboard` directly

This commit is contained in:
Héctor Ramón Jiménez 2021-03-11 03:40:15 +01:00
parent ae517b9fa0
commit a365998264
1 changed files with 14 additions and 4 deletions

View File

@ -20,17 +20,17 @@ impl Clipboard {
Clipboard { state }
}
}
impl iced_native::Clipboard for Clipboard {
fn read(&self) -> Option<String> {
/// Reads the current content of the [`Clipboard`] as text.
pub fn read(&self) -> Option<String> {
match &self.state {
State::Connected(clipboard) => clipboard.read().ok(),
State::Unavailable => None,
}
}
fn write(&mut self, contents: String) {
/// Writes the given text contents to the [`Clipboard`].
pub fn write(&mut self, contents: String) {
match &mut self.state {
State::Connected(clipboard) => match clipboard.write(contents) {
Ok(()) => {}
@ -42,3 +42,13 @@ impl iced_native::Clipboard for Clipboard {
}
}
}
impl iced_native::Clipboard for Clipboard {
fn read(&self) -> Option<String> {
self.read()
}
fn write(&mut self, contents: String) {
self.write(contents)
}
}