diff options
author | Matthias Sieber <[email protected]> | 2018-08-02 00:40:43 +0100 |
---|---|---|
committer | Matthias Sieber <[email protected]> | 2018-08-02 00:40:43 +0100 |
commit | b640970819482aa61eb5a7a661644e8f41a5aed6 (patch) | |
tree | a4db950741a2aa99881e55e38bee4e57121292e6 /src | |
parent | cb93bc02b13432ccfe5e231ebde1edd033a2b388 (diff) |
changes as suggested by clippy
Diffstat (limited to 'src')
-rw-r--r-- | src/content.rs | 22 | ||||
-rw-r--r-- | src/main.rs | 12 |
2 files changed, 15 insertions, 19 deletions
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<String, reqwest::Error> { | |||
54 | // format to plain text | 54 | // format to plain text |
55 | let extract = extract.replace("\\\\", "\\"); | 55 | let extract = extract.replace("\\\\", "\\"); |
56 | 56 | ||
57 | Ok(format!("{}", extract)) | 57 | Ok(extract.to_string()) |
58 | } | 58 | } |
59 | // ignore non strings | 59 | // ignore non strings |
60 | _ => Ok(format!("This page does not exist anymore")), | 60 | _ => Ok("This page does not exist anymore".to_string()), |
61 | } | 61 | } |
62 | } | 62 | } |
63 | 63 | ||
64 | pub fn extract_formatter(extract: String) -> StyledString { | 64 | pub fn extract_formatter(extract: &str) -> StyledString { |
65 | let mut formatted = StyledString::new(); | 65 | let mut formatted = StyledString::new(); |
66 | 66 | ||
67 | let heading = Regex::new(r"^== (?P<d>.*) ==$").unwrap(); | 67 | let heading = Regex::new(r"^== (?P<d>.*) ==$").unwrap(); |
@@ -103,10 +103,8 @@ pub fn get_search_results(search: &str) -> Result<Vec<String>, reqwest::Error> { | |||
103 | 103 | ||
104 | let mut results: Vec<String> = vec![]; | 104 | let mut results: Vec<String> = vec![]; |
105 | for item in v[1].as_array().unwrap() { | 105 | for item in v[1].as_array().unwrap() { |
106 | match item { | 106 | if let Value::String(x) = item { |
107 | Value::String(x) => results.push(x.to_string()), | 107 | results.push(x.to_string()) |
108 | // ignore non strings | ||
109 | _ => (), | ||
110 | } | 108 | } |
111 | } | 109 | } |
112 | Ok(results) | 110 | Ok(results) |
@@ -135,21 +133,21 @@ pub fn get_links(v: &Value) -> Result<Vec<String>, reqwest::Error> { | |||
135 | Ok(links) | 133 | Ok(links) |
136 | } | 134 | } |
137 | 135 | ||
138 | pub fn pop_error(s: &mut Cursive, msg: String) { | 136 | pub fn pop_error(s: &mut Cursive, msg: &str) { |
139 | s.add_layer(Dialog::text(format!("{}", msg)).button("Ok", |s| s.quit())); | 137 | s.add_layer(Dialog::text(msg.to_string()).button("Ok", |s| s.quit())); |
140 | } | 138 | } |
141 | 139 | ||
142 | pub fn handler(e: reqwest::Error) -> String { | 140 | pub fn handler(e: &reqwest::Error) -> String { |
143 | let mut msg: String = String::new(); | 141 | let mut msg: String = String::new(); |
144 | if e.is_http() { | 142 | if e.is_http() { |
145 | match e.url() { | 143 | match e.url() { |
146 | None => msg.push_str(&format!("No URL given")), | 144 | None => msg.push_str(&"No URL given"), |
147 | Some(url) => msg.push_str(&format!("Problem making request to: {}", url)), | 145 | Some(url) => msg.push_str(&format!("Problem making request to: {}", url)), |
148 | } | 146 | } |
149 | } | 147 | } |
150 | 148 | ||
151 | if e.is_redirect() { | 149 | if e.is_redirect() { |
152 | msg.push_str(&format!("server redirecting too many times or making loop")); | 150 | msg.push_str(&"server redirecting too many times or making loop"); |
153 | } | 151 | } |
154 | 152 | ||
155 | msg | 153 | 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; | |||
6 | extern crate lazy_static; | 6 | extern crate lazy_static; |
7 | 7 | ||
8 | use cursive::traits::*; | 8 | use cursive::traits::*; |
9 | use cursive::views::{ | 9 | use cursive::views::{Dialog, DummyView, EditView, LinearLayout, OnEventView, SelectView, TextView}; |
10 | Dialog, DummyView, EditView, LinearLayout, OnEventView, SelectView, TextView, | ||
11 | }; | ||
12 | use cursive::Cursive; | 10 | use cursive::Cursive; |
13 | 11 | ||
14 | use serde_json::Value; | 12 | use serde_json::Value; |
@@ -83,7 +81,7 @@ fn search(s: &mut Cursive) { | |||
83 | let mut result = vec![]; | 81 | let mut result = vec![]; |
84 | match get_search_results(&search) { | 82 | match get_search_results(&search) { |
85 | Ok(x) => result = x, | 83 | Ok(x) => result = x, |
86 | Err(e) => pop_error(s, handler(e)), | 84 | Err(e) => pop_error(s, &handler(&e)), |
87 | }; | 85 | }; |
88 | let choose_result = SelectView::<String>::new() | 86 | let choose_result = SelectView::<String>::new() |
89 | .with_all_str(result) | 87 | .with_all_str(result) |
@@ -132,15 +130,15 @@ fn on_submit(s: &mut Cursive, name: &str) { | |||
132 | 130 | ||
133 | match get_extract(&v) { | 131 | match get_extract(&v) { |
134 | Ok(x) => extract = x, | 132 | Ok(x) => extract = x, |
135 | Err(e) => pop_error(s, handler(e)), | 133 | Err(e) => pop_error(s, &handler(&e)), |
136 | }; | 134 | }; |
137 | match get_links(&v) { | 135 | match get_links(&v) { |
138 | Ok(x) => link_vec = x, | 136 | Ok(x) => link_vec = x, |
139 | Err(e) => pop_error(s, handler(e)), | 137 | Err(e) => pop_error(s, &handler(&e)), |
140 | }; | 138 | }; |
141 | 139 | ||
142 | // get the act together | 140 | // get the act together |
143 | let article_content = TextView::new(extract_formatter(extract)).scrollable(); | 141 | let article_content = TextView::new(extract_formatter(&extract)).scrollable(); |
144 | 142 | ||
145 | let links = SelectView::<String>::new() | 143 | let links = SelectView::<String>::new() |
146 | .with_all_str(link_vec) | 144 | .with_all_str(link_vec) |