Appeased clippy::needless_pass_by_value

This commit is contained in:
Xithrius 2022-12-16 10:08:17 -08:00
parent 4ddaf5b733
commit 21488160f7
No known key found for this signature in database
GPG Key ID: DADE524BA67AA52E
8 changed files with 36 additions and 33 deletions

View File

@ -7,7 +7,6 @@
clippy::struct_excessive_bools,
clippy::unused_self,
clippy::future_not_send,
clippy::needless_pass_by_value,
clippy::suboptimal_flops
)]

View File

@ -51,7 +51,7 @@ fn reset_terminal() {
execute!(stdout(), LeaveAlternateScreen, ResetCursorShape).unwrap();
}
fn init_terminal(cursor_shape: CursorType) -> Terminal<CrosstermBackend<Stdout>> {
fn init_terminal(cursor_shape: &CursorType) -> Terminal<CrosstermBackend<Stdout>> {
enable_raw_mode().unwrap();
let cursor_type = match cursor_shape {
@ -110,7 +110,7 @@ pub async fn ui_driver(
})
.await;
let mut terminal = init_terminal(config.frontend.cursor_shape.clone());
let mut terminal = init_terminal(&config.frontend.cursor_shape);
terminal.clear().unwrap();

View File

@ -29,7 +29,7 @@ pub fn render_chat_box<T: Backend>(window: WindowAttributes<T>, mention_suggesti
'/' => {
let possible_suggestion = suggestion_query(
&current_input[1..],
COMMANDS
&COMMANDS
.iter()
.map(ToString::to_string)
.collect::<Vec<String>>(),
@ -41,7 +41,7 @@ pub fn render_chat_box<T: Backend>(window: WindowAttributes<T>, mention_suggesti
}
'@' => {
let possible_suggestion =
suggestion_query(&current_input[1..], app.storage.get("mentions"));
suggestion_query(&current_input[1..], &app.storage.get("mentions"));
let default_suggestion = possible_suggestion.clone();

View File

@ -19,8 +19,8 @@ const TABS_TO_RENDER: [State; 5] = [
pub fn render_state_tabs<T: Backend>(
frame: &mut Frame<T>,
layout: LayoutAttributes,
current_state: State,
layout: &LayoutAttributes,
current_state: &State,
) {
let tab_titles = TABS_TO_RENDER
.iter()
@ -40,7 +40,7 @@ pub fn render_state_tabs<T: Backend>(
.select(
TABS_TO_RENDER
.iter()
.position(|s| s == &current_state)
.position(|s| s == current_state)
.unwrap(),
);

View File

@ -59,6 +59,8 @@ pub fn render_insert_box<T: Backend>(
let valid_input =
input_validation.map_or(true, |check_func| check_func(current_input.to_string()));
let binding = [TitleStyle::Single(box_title)];
let paragraph = Paragraph::new(Spans::from(vec![
Span::raw(current_input),
Span::styled(
@ -78,7 +80,7 @@ pub fn render_insert_box<T: Backend>(
Block::default()
.borders(Borders::ALL)
.title(title_spans(
vec![TitleStyle::Single(box_title)],
&binding,
Style::default().fg(Color::Red).add_modifier(Modifier::BOLD),
))
.border_style(Style::default().fg(if valid_input {

View File

@ -27,7 +27,7 @@ pub fn render_channel_switcher<T: Backend>(window: WindowAttributes<T>, channel_
let suggestion = if channel_suggestions {
suggestion_query(
input_buffer,
app.storage
&app.storage
.get("channels")
.iter()
.map(ToString::to_string)

View File

@ -206,26 +206,28 @@ pub fn draw_ui<T: Backend>(frame: &mut Frame<T>, app: &mut App, config: &Complet
.format(&config.frontend.date_format)
.to_string();
let spans = [
TitleStyle::Combined("Time", &current_time),
TitleStyle::Combined("Channel", config.twitch.channel.as_str()),
TitleStyle::Custom(Span::styled(
if app.filters.reversed() {
"retliF"
} else {
"Filter"
},
Style::default()
.add_modifier(Modifier::BOLD)
.fg(if app.filters.enabled() {
Color::Green
} else {
Color::Red
}),
)),
];
let chat_title = if config.frontend.title_shown {
Spans::from(title_spans(
vec![
TitleStyle::Combined("Time", &current_time),
TitleStyle::Combined("Channel", config.twitch.channel.as_str()),
TitleStyle::Custom(Span::styled(
if app.filters.reversed() {
"retliF"
} else {
"Filter"
},
Style::default()
.add_modifier(Modifier::BOLD)
.fg(if app.filters.enabled() {
Color::Green
} else {
Color::Red
}),
)),
],
&spans,
Style::default().fg(Color::Red).add_modifier(Modifier::BOLD),
))
} else {
@ -246,7 +248,7 @@ pub fn draw_ui<T: Backend>(frame: &mut Frame<T>, app: &mut App, config: &Complet
frame.render_widget(table, layout.first_chunk());
if config.frontend.state_tabs {
components::render_state_tabs(frame, layout.clone(), app.state.clone());
components::render_state_tabs(frame, &layout, &app.state);
}
let window = WindowAttributes::new(frame, app, layout, config.frontend.state_tabs);

View File

@ -49,7 +49,7 @@ pub enum TitleStyle<'a> {
Custom(Span<'a>),
}
pub fn title_spans(contents: Vec<TitleStyle>, style: Style) -> Vec<Span> {
pub fn title_spans<'a>(contents: &'a [TitleStyle<'a>], style: Style) -> Vec<Span<'a>> {
let mut complete = Vec::new();
for (i, item) in contents.iter().enumerate() {
@ -73,7 +73,7 @@ pub fn title_spans(contents: Vec<TitleStyle>, style: Style) -> Vec<Span> {
complete
}
pub fn suggestion_query(search: &str, possibilities: Vec<String>) -> Option<String> {
pub fn suggestion_query(search: &str, possibilities: &[String]) -> Option<String> {
possibilities
.iter()
.filter(|s| s.starts_with(search))
@ -160,7 +160,7 @@ mod tests {
#[test]
fn test_2_dimensional_vector_to_spans() {
let s = Spans::from(title_spans(
vec![TitleStyle::Combined("Time", "Some time")],
&[TitleStyle::Combined("Time", "Some time")],
Style::default().fg(Color::Red).add_modifier(Modifier::BOLD),
));
@ -171,7 +171,7 @@ mod tests {
fn test_partial_suggestion_output() {
let v = vec!["Nope".to_string()];
let output = suggestion_query("No", v);
let output = suggestion_query("No", &v);
assert_eq!(output, Some("Nope".to_string()));
}