Merge pull request #1106 from RamType0/RemoveUnnecessaryStringAllocationInExample

Remove unnecessary String allocation
This commit is contained in:
Héctor Ramón 2021-11-10 23:59:35 +07:00 committed by GitHub
commit f084ed8df1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 12 deletions

View file

@ -128,7 +128,7 @@ impl Counter {
) )
.push( .push(
// We show the value of the counter here // We show the value of the counter here
Text::new(&self.value.to_string()).size(50), Text::new(self.value.to_string()).size(50),
) )
.push( .push(
// The decrement button. We tell it to produce a // The decrement button. We tell it to produce a

View file

@ -72,7 +72,7 @@ impl Sandbox for ScrollableDemo {
column.push( column.push(
Radio::new( Radio::new(
*option, *option,
&format!("{:?}", option), format!("{:?}", option),
Some(*theme), Some(*theme),
Message::ThemeChanged, Message::ThemeChanged,
) )

View file

@ -60,7 +60,7 @@ impl Sandbox for Styling {
column.push( column.push(
Radio::new( Radio::new(
*theme, *theme,
&format!("{:?}", theme), format!("{:?}", theme),
Some(self.theme), Some(self.theme),
Message::ThemeChanged, Message::ThemeChanged,
) )

View file

@ -376,7 +376,7 @@ impl Controls {
.spacing(20) .spacing(20)
.align_items(Alignment::Center) .align_items(Alignment::Center)
.push( .push(
Text::new(&format!( Text::new(format!(
"{} {} left", "{} {} left",
tasks_left, tasks_left,
if tasks_left == 1 { "task" } else { "tasks" } if tasks_left == 1 { "task" } else { "tasks" }
@ -466,7 +466,7 @@ const ICONS: Font = Font::External {
}; };
fn icon(unicode: char) -> Text { fn icon(unicode: char) -> Text {
Text::new(&unicode.to_string()) Text::new(unicode.to_string())
.font(ICONS) .font(ICONS)
.width(Length::Units(20)) .width(Length::Units(20))
.horizontal_alignment(alignment::Horizontal::Center) .horizontal_alignment(alignment::Horizontal::Center)

View file

@ -417,7 +417,7 @@ impl<'a> Step {
StepMessage::SliderChanged, StepMessage::SliderChanged,
)) ))
.push( .push(
Text::new(&value.to_string()) Text::new(value.to_string())
.width(Length::Fill) .width(Length::Fill)
.horizontal_alignment(alignment::Horizontal::Center), .horizontal_alignment(alignment::Horizontal::Center),
) )
@ -464,7 +464,7 @@ impl<'a> Step {
StepMessage::SpacingChanged, StepMessage::SpacingChanged,
)) ))
.push( .push(
Text::new(&format!("{} px", spacing)) Text::new(format!("{} px", spacing))
.width(Length::Fill) .width(Length::Fill)
.horizontal_alignment(alignment::Horizontal::Center), .horizontal_alignment(alignment::Horizontal::Center),
); );
@ -496,9 +496,7 @@ impl<'a> Step {
.padding(20) .padding(20)
.spacing(20) .spacing(20)
.push(Text::new("You can change its size:")) .push(Text::new("You can change its size:"))
.push( .push(Text::new(format!("This text is {} pixels", size)).size(size))
Text::new(&format!("This text is {} pixels", size)).size(size),
)
.push(Slider::new( .push(Slider::new(
size_slider, size_slider,
10..=70, 10..=70,
@ -518,7 +516,7 @@ impl<'a> Step {
.padding(20) .padding(20)
.spacing(20) .spacing(20)
.push(Text::new("And its color:")) .push(Text::new("And its color:"))
.push(Text::new(&format!("{:?}", color)).color(color)) .push(Text::new(format!("{:?}", color)).color(color))
.push(color_sliders); .push(color_sliders);
Self::container("Text") Self::container("Text")
@ -589,7 +587,7 @@ impl<'a> Step {
StepMessage::ImageWidthChanged, StepMessage::ImageWidthChanged,
)) ))
.push( .push(
Text::new(&format!("Width: {} px", width.to_string())) Text::new(format!("Width: {} px", width.to_string()))
.width(Length::Fill) .width(Length::Fill)
.horizontal_alignment(alignment::Horizontal::Center), .horizontal_alignment(alignment::Horizontal::Center),
) )