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 --- readme.md | 12 ++++++------ src/content.rs | 22 ++++++++++------------ src/main.rs | 12 +++++------- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/readme.md b/readme.md index d6bfc3c..8d908d0 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ ![banner.png](https://0x0.st/sVMH.png) -Browse mediawiki pages from the command line. +Browse mediawiki pages from the command line. ## Installation This project uses [Cursive crate](https://github.com/gyscos/Cursive), so before installing `Taizen` @@ -9,19 +9,19 @@ make sure you have installed necessary Cursive [dependencies](https://github.com ```shell git clone https://github.com/nerdypepper/taizen cd taizen -cargo run +cargo run --release ``` ## Usage Taizen uses a **stack** like model. -Articles are opened on new layers, pop a layer to go back. -Hit `s` to search -Hit `q` to quit +Articles are opened on new layers, pop a layer to go back. +Hit `s` to search +Hit `q` to quit Hit `t` to pop a layer from the article stack You can now view wikipedia pages in different languages, by passing the -language code as a commandline arg. +language code as a commandline arg. [List of language codes](https://en.wikipedia.org/wiki/List_of_Wikipedias#Detailed_list) ``` 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