From 13154e1b0ad014007137cd35511221bb7beab030 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 10 Feb 2026 20:41:26 +0800 Subject: [PATCH] gpui: Impl `Cow<'static, str>` to `IntoElement` (#48585) Release Notes: - N/A Make this change to let `div().child(...)` support any types that have impl `Into`, for example: `Cow<'static, str>`. ```rs // From somewhere get a `Cow<'static, str>` type. let label = Cow::Borrowed("Hello"); div() .child(label); ``` --- crates/gpui/src/elements/text.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/gpui/src/elements/text.rs b/crates/gpui/src/elements/text.rs index 770c1f871432afbecc9ffd4e903dfeddcfcba6ee..ab861be5a29fcbfb575a48cf743407f1c6e927d6 100644 --- a/crates/gpui/src/elements/text.rs +++ b/crates/gpui/src/elements/text.rs @@ -84,6 +84,14 @@ impl IntoElement for String { } } +impl IntoElement for Cow<'static, str> { + type Element = SharedString; + + fn into_element(self) -> Self::Element { + self.into() + } +} + impl Element for SharedString { type RequestLayoutState = TextLayout; type PrepaintState = (); @@ -924,3 +932,17 @@ impl IntoElement for InteractiveText { self } } + +#[cfg(test)] +mod tests { + #[test] + fn test_into_element_for() { + use crate::{ParentElement as _, SharedString, div}; + use std::borrow::Cow; + + let _ = div().child("static str"); + let _ = div().child("String".to_string()); + let _ = div().child(Cow::Borrowed("Cow")); + let _ = div().child(SharedString::from("SharedString")); + } +}