gpui: Implement From trait for Clipboard related structs (#27585)

Implement the From trait for some simple conversations between Clipboard
related structs.

This PR only adds the From trait implementations and doesn't touch any
code. In a future PR we can simplify usage throughout the codebase, such
as:

```rust
// impl ClipboardString
fn new(text: String) -> Self {
    Self::from(text)
}
```

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
tidely 2025-03-28 23:38:05 +02:00 committed by GitHub
parent 9445005bff
commit 01b400ea29
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1335,6 +1335,44 @@ impl ClipboardItem {
}
}
impl From<ClipboardString> for ClipboardEntry {
fn from(value: ClipboardString) -> Self {
Self::String(value)
}
}
impl From<String> for ClipboardEntry {
fn from(value: String) -> Self {
Self::from(ClipboardString::from(value))
}
}
impl From<Image> for ClipboardEntry {
fn from(value: Image) -> Self {
Self::Image(value)
}
}
impl From<ClipboardEntry> for ClipboardItem {
fn from(value: ClipboardEntry) -> Self {
Self {
entries: vec![value],
}
}
}
impl From<String> for ClipboardItem {
fn from(value: String) -> Self {
Self::from(ClipboardEntry::from(value))
}
}
impl From<Image> for ClipboardItem {
fn from(value: Image) -> Self {
Self::from(ClipboardEntry::from(value))
}
}
/// One of the editor's supported image formats (e.g. PNG, JPEG) - used when dealing with images in the clipboard
#[derive(Clone, Copy, Debug, Eq, PartialEq, EnumIter, Hash)]
pub enum ImageFormat {
@ -1503,3 +1541,12 @@ impl ClipboardString {
hasher.finish()
}
}
impl From<String> for ClipboardString {
fn from(value: String) -> Self {
Self {
text: value,
metadata: None,
}
}
}