Introduce Kind in core::clipboard

This commit is contained in:
Héctor Ramón Jiménez 2024-02-13 03:14:08 +01:00
parent 4155edab8d
commit 508b3fe1f1
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
9 changed files with 97 additions and 130 deletions

View file

@ -4,16 +4,21 @@
/// applications.
pub trait Clipboard {
/// Reads the current content of the [`Clipboard`] as text.
fn read(&self) -> Option<String>;
fn read(&self, kind: Kind) -> Option<String>;
/// Writes the given text contents to the [`Clipboard`].
fn write(&mut self, contents: String);
fn write(&mut self, kind: Kind, contents: String);
}
/// Reads the current content of Primary as text.
fn read_primary(&self) -> Option<String>;
/// Writes the given text contents to Primary.
fn write_primary(&mut self, contents: String);
/// The kind of [`Clipboard`].
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Kind {
/// The standard clipboard.
Standard,
/// The primary clipboard.
///
/// Normally only present in X11 and Wayland.
Primary,
}
/// A null implementation of the [`Clipboard`] trait.
@ -21,15 +26,9 @@ pub trait Clipboard {
pub struct Null;
impl Clipboard for Null {
fn read(&self) -> Option<String> {
fn read(&self, _kind: Kind) -> Option<String> {
None
}
fn write(&mut self, _contents: String) {}
fn read_primary(&self) -> Option<String> {
None
}
fn write_primary(&mut self, _contents: String) {}
fn write(&mut self, _kind: Kind, _contents: String) {}
}