Skip to content

Commit 01b400e

Browse files
authored
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 ...
1 parent 9445005 commit 01b400e

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

crates/gpui/src/platform.rs

+47
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,44 @@ impl ClipboardItem {
13351335
}
13361336
}
13371337

1338+
impl From<ClipboardString> for ClipboardEntry {
1339+
fn from(value: ClipboardString) -> Self {
1340+
Self::String(value)
1341+
}
1342+
}
1343+
1344+
impl From<String> for ClipboardEntry {
1345+
fn from(value: String) -> Self {
1346+
Self::from(ClipboardString::from(value))
1347+
}
1348+
}
1349+
1350+
impl From<Image> for ClipboardEntry {
1351+
fn from(value: Image) -> Self {
1352+
Self::Image(value)
1353+
}
1354+
}
1355+
1356+
impl From<ClipboardEntry> for ClipboardItem {
1357+
fn from(value: ClipboardEntry) -> Self {
1358+
Self {
1359+
entries: vec![value],
1360+
}
1361+
}
1362+
}
1363+
1364+
impl From<String> for ClipboardItem {
1365+
fn from(value: String) -> Self {
1366+
Self::from(ClipboardEntry::from(value))
1367+
}
1368+
}
1369+
1370+
impl From<Image> for ClipboardItem {
1371+
fn from(value: Image) -> Self {
1372+
Self::from(ClipboardEntry::from(value))
1373+
}
1374+
}
1375+
13381376
/// One of the editor's supported image formats (e.g. PNG, JPEG) - used when dealing with images in the clipboard
13391377
#[derive(Clone, Copy, Debug, Eq, PartialEq, EnumIter, Hash)]
13401378
pub enum ImageFormat {
@@ -1503,3 +1541,12 @@ impl ClipboardString {
15031541
hasher.finish()
15041542
}
15051543
}
1544+
1545+
impl From<String> for ClipboardString {
1546+
fn from(value: String) -> Self {
1547+
Self {
1548+
text: value,
1549+
metadata: None,
1550+
}
1551+
}
1552+
}

0 commit comments

Comments
 (0)