From cc16c3e56def18cd8197b89e033a7255fb985cb4 Mon Sep 17 00:00:00 2001 From: JEEVITHA KANNAN K S Date: Tue, 1 Oct 2024 12:11:45 +0530 Subject: [PATCH] Use string instead of box::leak --- tui/src/state.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tui/src/state.rs b/tui/src/state.rs index 9e12b788..b0b582ad 100644 --- a/tui/src/state.rs +++ b/tui/src/state.rs @@ -56,7 +56,7 @@ pub struct AppState { selected_commands: Vec, drawable: bool, #[cfg(feature = "tips")] - tip: &'static str, + tip: String, } pub enum Focus { @@ -363,7 +363,7 @@ impl AppState { }; #[cfg(feature = "tips")] - let bottom_title = Line::from(self.tip.bold().blue()).right_aligned(); + let bottom_title = Line::from(self.tip.clone().bold().blue()).right_aligned(); #[cfg(not(feature = "tips"))] let bottom_title = ""; @@ -686,13 +686,13 @@ impl AppState { const TIPS: &str = include_str!("../cool_tips.txt"); #[cfg(feature = "tips")] -fn get_random_tip() -> &'static str { +fn get_random_tip() -> String { let tips: Vec<&str> = TIPS.lines().collect(); if tips.is_empty() { - return ""; + return "".to_string(); } let mut rng = rand::thread_rng(); let random_index = rng.gen_range(0..tips.len()); - Box::leak(format!(" {} ", tips[random_index]).into_boxed_str()) + format!(" {} ", tips[random_index]) }