aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay <[email protected]>2018-08-02 17:31:14 +0100
committerGitHub <[email protected]>2018-08-02 17:31:14 +0100
commit4b49ddfab6a5a957d651795bedd9f26dfc0a4635 (patch)
treea4db950741a2aa99881e55e38bee4e57121292e6 /src
parentcb93bc02b13432ccfe5e231ebde1edd033a2b388 (diff)
parentb640970819482aa61eb5a7a661644e8f41a5aed6 (diff)
Merge pull request #11 from manonthemat/master
changes as suggested by clippy
Diffstat (limited to 'src')
-rw-r--r--src/content.rs22
-rw-r--r--src/main.rs12
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
64pub fn extract_formatter(extract: String) -> StyledString { 64pub 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
138pub fn pop_error(s: &mut Cursive, msg: String) { 136pub 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
142pub fn handler(e: reqwest::Error) -> String { 140pub 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;
6extern crate lazy_static; 6extern crate lazy_static;
7 7
8use cursive::traits::*; 8use cursive::traits::*;
9use cursive::views::{ 9use cursive::views::{Dialog, DummyView, EditView, LinearLayout, OnEventView, SelectView, TextView};
10 Dialog, DummyView, EditView, LinearLayout, OnEventView, SelectView, TextView,
11};
12use cursive::Cursive; 10use cursive::Cursive;
13 11
14use serde_json::Value; 12use 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)