From b640970819482aa61eb5a7a661644e8f41a5aed6 Mon Sep 17 00:00:00 2001 From: Matthias Sieber Date: Wed, 1 Aug 2018 16:40:43 -0700 Subject: changes as suggested by clippy --- src/content.rs | 22 ++++++++++------------ src/main.rs | 12 +++++------- 2 files changed, 15 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/content.rs b/src/content.rs index 8b48411..0f81149 100644 --- a/src/content.rs +++ b/src/content.rs @@ -54,14 +54,14 @@ pub fn get_extract(v: &Value) -> Result { // format to plain text let extract = extract.replace("\\\\", "\\"); - Ok(format!("{}", extract)) + Ok(extract.to_string()) } // ignore non strings - _ => Ok(format!("This page does not exist anymore")), + _ => Ok("This page does not exist anymore".to_string()), } } -pub fn extract_formatter(extract: String) -> StyledString { +pub fn extract_formatter(extract: &str) -> StyledString { let mut formatted = StyledString::new(); let heading = Regex::new(r"^== (?P.*) ==$").unwrap(); @@ -103,10 +103,8 @@ pub fn get_search_results(search: &str) -> Result, reqwest::Error> { let mut results: Vec = vec![]; for item in v[1].as_array().unwrap() { - match item { - Value::String(x) => results.push(x.to_string()), - // ignore non strings - _ => (), + if let Value::String(x) = item { + results.push(x.to_string()) } } Ok(results) @@ -135,21 +133,21 @@ pub fn get_links(v: &Value) -> Result, reqwest::Error> { Ok(links) } -pub fn pop_error(s: &mut Cursive, msg: String) { - s.add_layer(Dialog::text(format!("{}", msg)).button("Ok", |s| s.quit())); +pub fn pop_error(s: &mut Cursive, msg: &str) { + s.add_layer(Dialog::text(msg.to_string()).button("Ok", |s| s.quit())); } -pub fn handler(e: reqwest::Error) -> String { +pub fn handler(e: &reqwest::Error) -> String { let mut msg: String = String::new(); if e.is_http() { match e.url() { - None => msg.push_str(&format!("No URL given")), + None => msg.push_str(&"No URL given"), Some(url) => msg.push_str(&format!("Problem making request to: {}", url)), } } if e.is_redirect() { - msg.push_str(&format!("server redirecting too many times or making loop")); + msg.push_str(&"server redirecting too many times or making loop"); } msg diff --git a/src/main.rs b/src/main.rs index fd01af8..85d25e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,9 +6,7 @@ extern crate serde_json; extern crate lazy_static; use cursive::traits::*; -use cursive::views::{ - Dialog, DummyView, EditView, LinearLayout, OnEventView, SelectView, TextView, -}; +use cursive::views::{Dialog, DummyView, EditView, LinearLayout, OnEventView, SelectView, TextView}; use cursive::Cursive; use serde_json::Value; @@ -83,7 +81,7 @@ fn search(s: &mut Cursive) { let mut result = vec![]; match get_search_results(&search) { Ok(x) => result = x, - Err(e) => pop_error(s, handler(e)), + Err(e) => pop_error(s, &handler(&e)), }; let choose_result = SelectView::::new() .with_all_str(result) @@ -132,15 +130,15 @@ fn on_submit(s: &mut Cursive, name: &str) { match get_extract(&v) { Ok(x) => extract = x, - Err(e) => pop_error(s, handler(e)), + Err(e) => pop_error(s, &handler(&e)), }; match get_links(&v) { Ok(x) => link_vec = x, - Err(e) => pop_error(s, handler(e)), + Err(e) => pop_error(s, &handler(&e)), }; // get the act together - let article_content = TextView::new(extract_formatter(extract)).scrollable(); + let article_content = TextView::new(extract_formatter(&extract)).scrollable(); let links = SelectView::::new() .with_all_str(link_vec) -- cgit v1.2.3