1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

Impl from Box<str> for WidgetText, RichText (#5309)

`Box<str>` is an immutable heap-allocated string slice.
This PR makes it more convenient to use them in labels for example.

Before this PR
```rust
let text: Box<str> = "Hello".into();
ui.label(text.into_string());

let text_ref: &Box<str> = &"Hello".into();
ui.label(text_ref.clone().into_string());
// or
ui.label(text_ref.as_ref());
// or
ui.label(&**text_ref);
```
After this PR
```rust
let text: Box<str> = "Hello".into();
ui.label(text);

let text_ref: &Box<str> = &"Hello".into();
ui.label(text_ref);
```

* [x] I have followed the instructions in the PR template
This commit is contained in:
Dimitris Papaioannou
2024-10-29 11:50:06 +02:00
committed by GitHub
parent 288c74e332
commit ebb4646358

View File

@@ -67,6 +67,27 @@ impl From<String> for RichText {
}
}
impl From<&Box<str>> for RichText {
#[inline]
fn from(text: &Box<str>) -> Self {
Self::new(text.clone())
}
}
impl From<&mut Box<str>> for RichText {
#[inline]
fn from(text: &mut Box<str>) -> Self {
Self::new(text.clone())
}
}
impl From<Box<str>> for RichText {
#[inline]
fn from(text: Box<str>) -> Self {
Self::new(text)
}
}
impl From<Cow<'_, str>> for RichText {
#[inline]
fn from(text: Cow<'_, str>) -> Self {
@@ -701,6 +722,20 @@ impl From<String> for WidgetText {
}
}
impl From<&Box<str>> for WidgetText {
#[inline]
fn from(text: &Box<str>) -> Self {
Self::RichText(RichText::new(text.clone()))
}
}
impl From<Box<str>> for WidgetText {
#[inline]
fn from(text: Box<str>) -> Self {
Self::RichText(RichText::new(text))
}
}
impl From<Cow<'_, str>> for WidgetText {
#[inline]
fn from(text: Cow<'_, str>) -> Self {