cargo clippy --fix

This commit is contained in:
Magnus Hovland Hoff 2022-04-03 14:29:35 +02:00
parent 9320d14d89
commit 95a73b9471
26 changed files with 62 additions and 110 deletions

View file

@ -34,10 +34,8 @@ fn main() {
let _ignore_failure = std::fs::remove_file(db_path); let _ignore_failure = std::fs::remove_file(db_path);
let connection = SqliteConnection::establish(db_path).expect(&format!( let connection = SqliteConnection::establish(db_path)
"Error esablishing a database connection to {}", .unwrap_or_else(|_| panic!("Error esablishing a database connection to {}", db_path));
db_path
));
// Integer is a dummy placeholder. Compiling fails when passing (). // Integer is a dummy placeholder. Compiling fails when passing ().
diesel::expression::sql_literal::sql::<diesel::sql_types::Integer>("PRAGMA foreign_keys = ON") diesel::expression::sql_literal::sql::<diesel::sql_types::Integer>("PRAGMA foreign_keys = ON")

View file

@ -23,7 +23,7 @@ lazy_static! {
#[cfg(feature = "dynamic-assets")] #[cfg(feature = "dynamic-assets")]
components.push("dynamic-assets".into()); components.push("dynamic-assets".into());
if let None = option_env!("CONTINUOUS_INTEGRATION") { if option_env!("CONTINUOUS_INTEGRATION").is_none() {
components.push("local-build".into()); components.push("local-build".into());
} }
@ -43,7 +43,7 @@ lazy_static! {
)); ));
} }
if components.len() > 0 { if !components.is_empty() {
format!("{} ({})", env!("CARGO_PKG_VERSION"), components.join(" ")) format!("{} ({})", env!("CARGO_PKG_VERSION"), components.join(" "))
} else { } else {
env!("CARGO_PKG_VERSION").to_string() env!("CARGO_PKG_VERSION").to_string()

View file

@ -23,17 +23,17 @@ impl CustomizeConnection<SqliteConnection, r2d2_diesel::Error> for SqliteInitial
fn on_acquire(&self, conn: &mut SqliteConnection) -> Result<(), r2d2_diesel::Error> { fn on_acquire(&self, conn: &mut SqliteConnection) -> Result<(), r2d2_diesel::Error> {
sql::<Integer>("PRAGMA foreign_keys = ON") sql::<Integer>("PRAGMA foreign_keys = ON")
.execute(conn) .execute(conn)
.map_err(|x| r2d2_diesel::Error::QueryError(x))?; .map_err(r2d2_diesel::Error::QueryError)?;
sqlfunc::markdown_to_fts::register_impl(conn, |text: String| { sqlfunc::markdown_to_fts::register_impl(conn, |text: String| {
rendering::render_markdown_for_fts(&text) rendering::render_markdown_for_fts(&text)
}) })
.map_err(|x| r2d2_diesel::Error::QueryError(x))?; .map_err(r2d2_diesel::Error::QueryError)?;
sqlfunc::theme_from_str_hash::register_impl(conn, |title: String| { sqlfunc::theme_from_str_hash::register_impl(conn, |title: String| {
theme::theme_from_str_hash(&title) theme::theme_from_str_hash(&title)
}) })
.map_err(|x| r2d2_diesel::Error::QueryError(x))?; .map_err(r2d2_diesel::Error::QueryError)?;
Ok(()) Ok(())
} }

View file

@ -1,4 +1,3 @@
use diff;
use std::fmt::Debug; use std::fmt::Debug;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]

View file

@ -1,6 +1,5 @@
use std::fmt::Debug; use std::fmt::Debug;
use diff;
use diff::Result::*; use diff::Result::*;
use super::chunk::Chunk; use super::chunk::Chunk;
@ -68,7 +67,7 @@ where
return Some(chunk); return Some(chunk);
} }
_ => { _ => {
if self.left.len() > 0 || self.right.len() > 0 { if !self.left.is_empty() || !self.right.is_empty() {
let chunk = Chunk(self.left, self.right); let chunk = Chunk(self.left, self.right);
self.left = &self.left[self.left.len()..]; self.left = &self.left[self.left.len()..];
self.right = &self.right[self.right.len()..]; self.right = &self.right[self.right.len()..];
@ -84,7 +83,6 @@ where
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use diff;
#[test] #[test]
fn simple_case() { fn simple_case() {

View file

@ -4,8 +4,6 @@ mod output;
use std::fmt::Debug; use std::fmt::Debug;
use diff;
use self::chunk_iterator::ChunkIterator; use self::chunk_iterator::ChunkIterator;
use self::output::Output::Resolved; use self::output::Output::Resolved;
use self::output::*; use self::output::*;
@ -132,7 +130,6 @@ pub fn merge_chars<'a>(a: &'a str, o: &'a str, b: &'a str) -> MergeResult<char>
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use diff;
use super::output::Output::*; use super::output::Output::*;
use super::output::*; use super::output::*;

View file

@ -1,6 +1,5 @@
use std::fmt::Debug; use std::fmt::Debug;
use diff;
use diff::Result::*; use diff::Result::*;
use super::chunk::Chunk; use super::chunk::Chunk;
@ -67,17 +66,16 @@ pub fn resolve<'a, Item: 'a + Debug + PartialEq + Copy>(chunk: Chunk<'a, Item>)
return Output::Resolved(choose_right(chunk.0)); return Output::Resolved(choose_right(chunk.0));
} }
return Output::Conflict( Output::Conflict(
choose_right(chunk.0), choose_right(chunk.0),
choose_left(chunk.0), choose_left(chunk.0),
choose_right(chunk.1), choose_right(chunk.1),
); )
} }
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use diff::Result::*;
#[test] #[test]
fn empty() { fn empty() {

View file

@ -1,5 +1,3 @@
use chrono;
use crate::theme::Theme; use crate::theme::Theme;
fn slug_link(slug: &str) -> &str { fn slug_link(slug: &str) -> &str {

View file

@ -34,7 +34,7 @@ pub fn render_markdown_for_fts(src: &str) -> String {
buf.push_str(&uri.replace(is_html_special, " ")); buf.push_str(&uri.replace(is_html_special, " "));
buf.push_str(") "); buf.push_str(") ");
} }
_ => buf.push_str(" "), _ => buf.push(' '),
} }
} }

View file

@ -1,5 +1,5 @@
use futures::{self, Future}; use futures::{self, Future};
use hyper;
use hyper::header::ContentType; use hyper::header::ContentType;
use hyper::server::*; use hyper::server::*;
@ -88,7 +88,7 @@ impl Resource for AboutResource {
None, // Hmm, should perhaps accept `base` as argument None, // Hmm, should perhaps accept `base` as argument
"About Sausagewiki", "About Sausagewiki",
Template { Template {
deps: &*LICENSE_INFOS, deps: *LICENSE_INFOS,
}, },
) )
.to_string(), .to_string(),

View file

@ -1,10 +1,8 @@
use chrono::{DateTime, Local, TimeZone}; use chrono::{DateTime, Local, TimeZone};
use futures::{self, Future}; use futures::{self, Future};
use hyper;
use hyper::header::{ContentType, Location}; use hyper::header::{ContentType, Location};
use hyper::server::*; use hyper::server::*;
use serde_json;
use serde_urlencoded;
use crate::assets::ScriptJs; use crate::assets::ScriptJs;
use crate::mimes::*; use crate::mimes::*;
@ -90,7 +88,7 @@ pub fn last_updated(article_id: i32, created: &DateTime<Local>, author: Option<&
.into_link() .into_link()
), ),
author: author.map(|author| Author { author: author.map(|author| Author {
author: &author, author,
history: format!( history: format!(
"_changes{}", "_changes{}",
QueryParameters::default() QueryParameters::default()
@ -134,7 +132,7 @@ impl Resource for ArticleResource {
last_updated: Some(&last_updated( last_updated: Some(&last_updated(
data.article_id, data.article_id,
&Local.from_utc_datetime(&data.created), &Local.from_utc_datetime(&data.created),
data.author.as_ref().map(|x| &**x), data.author.as_deref(),
)), )),
edit: self.edit, edit: self.edit,
cancel_url: Some(data.link()), cancel_url: Some(data.link()),
@ -213,7 +211,7 @@ impl Resource for ArticleResource {
last_updated: &last_updated( last_updated: &last_updated(
updated.article_id, updated.article_id,
&Local.from_utc_datetime(&updated.created), &Local.from_utc_datetime(&updated.created),
updated.author.as_ref().map(|x| &**x), updated.author.as_deref(),
), ),
}) })
.expect("Should never fail"), .expect("Should never fail"),
@ -245,7 +243,7 @@ impl Resource for ArticleResource {
last_updated: &last_updated( last_updated: &last_updated(
base_article.article_id, base_article.article_id,
&Local.from_utc_datetime(&base_article.created), &Local.from_utc_datetime(&base_article.created),
base_article.author.as_ref().map(|x| &**x), base_article.author.as_deref(),
), ),
}) })
.expect("Should never fail"), .expect("Should never fail"),
@ -301,7 +299,7 @@ impl Resource for ArticleResource {
last_updated: Some(&last_updated( last_updated: Some(&last_updated(
base_article.article_id, base_article.article_id,
&Local.from_utc_datetime(&base_article.created), &Local.from_utc_datetime(&base_article.created),
base_article.author.as_ref().map(|x| &**x), base_article.author.as_deref(),
)), )),
edit: true, edit: true,
cancel_url: Some(base_article.link()), cancel_url: Some(base_article.link()),

View file

@ -1,6 +1,6 @@
use chrono::{DateTime, Local, TimeZone}; use chrono::{DateTime, Local, TimeZone};
use futures::{self, Future}; use futures::{self, Future};
use hyper;
use hyper::header::ContentType; use hyper::header::ContentType;
use hyper::server::*; use hyper::server::*;
@ -55,7 +55,7 @@ pub fn timestamp_and_author(
.into_link() .into_link()
), ),
author: author.map(|author| Author { author: author.map(|author| Author {
author: &author, author,
history: format!( history: format!(
"_changes{}", "_changes{}",
QueryParameters::default() QueryParameters::default()
@ -107,7 +107,7 @@ impl Resource for ArticleRevisionResource {
data.sequence_number, data.sequence_number,
data.article_id, data.article_id,
&Local.from_utc_datetime(&data.created), &Local.from_utc_datetime(&data.created),
data.author.as_ref().map(|x| &**x), data.author.as_deref(),
), ),
diff_link: if data.revision > 1 { diff_link: if data.revision > 1 {
Some(format!( Some(format!(

View file

@ -1,10 +1,8 @@
use diesel;
use futures::future::{done, finished}; use futures::future::{done, finished};
use futures::{self, Future}; use futures::{self, Future};
use hyper;
use hyper::header::ContentType; use hyper::header::ContentType;
use hyper::server::*; use hyper::server::*;
use serde_urlencoded;
use crate::mimes::*; use crate::mimes::*;
use crate::schema::article_revisions; use crate::schema::article_revisions;
@ -75,7 +73,7 @@ impl QueryParameters {
pub fn into_link(self) -> String { pub fn into_link(self) -> String {
let args = serde_urlencoded::to_string(self).expect("Serializing to String cannot fail"); let args = serde_urlencoded::to_string(self).expect("Serializing to String cannot fail");
if args.len() > 0 { if !args.is_empty() {
format!("?{}", args) format!("?{}", args)
} else { } else {
"_changes".to_owned() "_changes".to_owned()
@ -127,7 +125,7 @@ impl ChangesLookup {
let limit = match params.limit { let limit = match params.limit {
None => Ok(DEFAULT_LIMIT), None => Ok(DEFAULT_LIMIT),
Some(x) if 1 <= x && x <= 100 => Ok(x), Some(x) if (1..=100).contains(&x) => Ok(x),
_ => Err("`limit` argument must be in range [1, 100]"), _ => Err("`limit` argument must be in range [1, 100]"),
}?; }?;
@ -309,7 +307,7 @@ impl Resource for ChangesResource {
fn subject_clause(&self) -> String { fn subject_clause(&self) -> String {
match self.resource.article_id { match self.resource.article_id {
Some(x) => format!(" <a href=\"_by_id/{}\">this article</a>", x), Some(x) => format!(" <a href=\"_by_id/{}\">this article</a>", x),
None => format!(" the wiki"), None => " the wiki".to_string(),
} }
} }
@ -332,8 +330,8 @@ impl Resource for ChangesResource {
} }
let (before, article_id, author, limit) = ( let (before, article_id, author, limit) = (
self.before.clone(), self.before,
self.article_id.clone(), self.article_id,
self.author.clone(), self.author.clone(),
self.limit, self.limit,
); );

View file

@ -1,12 +1,10 @@
use std::fmt; use std::fmt;
use diff;
use futures::future::done; use futures::future::done;
use futures::{self, Future}; use futures::{self, Future};
use hyper;
use hyper::header::ContentType; use hyper::header::ContentType;
use hyper::server::*; use hyper::server::*;
use serde_urlencoded;
use crate::mimes::*; use crate::mimes::*;
use crate::models::ArticleRevision; use crate::models::ArticleRevision;
@ -127,7 +125,7 @@ impl Resource for DiffResource {
let consecutive = self.to.revision - self.from.revision == 1; let consecutive = self.to.revision - self.from.revision == 1;
let author = match consecutive { let author = match consecutive {
true => self.to.author.as_ref().map(|x| &**x), true => self.to.author.as_deref(),
false => None, false => None,
}; };

View file

@ -1,5 +1,5 @@
use futures::{self, Future}; use futures::{self, Future};
use hyper;
use hyper::header::ContentType; use hyper::header::ContentType;
use hyper::server::*; use hyper::server::*;

View file

@ -1,9 +1,7 @@
use futures::{self, Future}; use futures::{self, Future};
use hyper;
use hyper::header::{ContentType, Location}; use hyper::header::{ContentType, Location};
use hyper::server::*; use hyper::server::*;
use serde_json;
use serde_urlencoded;
use crate::assets::ScriptJs; use crate::assets::ScriptJs;
use crate::mimes::*; use crate::mimes::*;
@ -100,7 +98,7 @@ impl Resource for NewArticleResource {
revision: NEW, revision: NEW,
last_updated: None, last_updated: None,
edit: self.edit, edit: self.edit,
cancel_url: self.slug.as_ref().map(|x| &**x), cancel_url: self.slug.as_deref(),
title: &title, title: &title,
raw: "", raw: "",
rendered: EMPTY_ARTICLE_MESSAGE, rendered: EMPTY_ARTICLE_MESSAGE,
@ -182,7 +180,7 @@ impl Resource for NewArticleResource {
last_updated: &super::article_resource::last_updated( last_updated: &super::article_resource::last_updated(
updated.article_id, updated.article_id,
&Local.from_utc_datetime(&updated.created), &Local.from_utc_datetime(&updated.created),
updated.author.as_ref().map(|x| &**x), updated.author.as_deref(),
), ),
}) })
.expect("Should never fail"), .expect("Should never fail"),

View file

@ -40,9 +40,9 @@ impl<T> PaginationStruct<T> {
pub fn _from_str<'a, T: serde::Deserialize<'a>>(s: &'a str) -> Result<Pagination<T>, Error> { pub fn _from_str<'a, T: serde::Deserialize<'a>>(s: &'a str) -> Result<Pagination<T>, Error> {
let pagination: PaginationStruct<T> = serde_urlencoded::from_str(s).map_err(|_| Error)?; // TODO Proper error reporting let pagination: PaginationStruct<T> = serde_urlencoded::from_str(s).map_err(|_| Error)?; // TODO Proper error reporting
Ok(pagination.into_enum()?) pagination.into_enum()
} }
pub fn from_fields<T>(after: Option<T>, before: Option<T>) -> Result<Pagination<T>, Error> { pub fn from_fields<T>(after: Option<T>, before: Option<T>) -> Result<Pagination<T>, Error> {
Ok(PaginationStruct { after, before }.into_enum()?) PaginationStruct { after, before }.into_enum()
} }

View file

@ -1,9 +1,7 @@
use futures::{self, Future}; use futures::{self, Future};
use hyper;
use hyper::header::{Accept, ContentType}; use hyper::header::{Accept, ContentType};
use hyper::server::*; use hyper::server::*;
use serde_json;
use serde_urlencoded;
use crate::mimes::*; use crate::mimes::*;
use crate::models::SearchResult; use crate::models::SearchResult;
@ -56,7 +54,7 @@ impl QueryParameters {
pub fn into_link(self) -> String { pub fn into_link(self) -> String {
let args = serde_urlencoded::to_string(self).expect("Serializing to String cannot fail"); let args = serde_urlencoded::to_string(self).expect("Serializing to String cannot fail");
if args.len() > 0 { if !args.is_empty() {
format!("_search?{}", args) format!("_search?{}", args)
} else { } else {
"_search".to_owned() "_search".to_owned()
@ -185,11 +183,7 @@ impl Resource for SearchResource {
} }
// TODO: Show a search "front page" when no query is given: // TODO: Show a search "front page" when no query is given:
let query = self let query = self.query.as_ref().cloned().unwrap_or("".to_owned());
.query
.as_ref()
.map(|x| x.clone())
.unwrap_or("".to_owned());
let data = self.state.search_query( let data = self.state.search_query(
query, query,
@ -224,7 +218,7 @@ impl Resource for SearchResource {
match &self.response_type { match &self.response_type {
&ResponseType::Json => Ok(head.with_body( &ResponseType::Json => Ok(head.with_body(
serde_json::to_string(&JsonResponse { serde_json::to_string(&JsonResponse {
query: self.query.as_ref().map(|x| &**x).unwrap_or(""), query: self.query.as_deref().unwrap_or(""),
hits: &data, hits: &data,
prev, prev,
next, next,
@ -236,7 +230,7 @@ impl Resource for SearchResource {
None, // Hmm, should perhaps accept `base` as argument None, // Hmm, should perhaps accept `base` as argument
"Search", "Search",
&Template { &Template {
query: self.query.as_ref().map(|x| &**x).unwrap_or(""), query: self.query.as_deref().unwrap_or(""),
hits: &data.iter().enumerate().collect::<Vec<_>>(), hits: &data.iter().enumerate().collect::<Vec<_>>(),
prev, prev,
next, next,

View file

@ -1,5 +1,5 @@
use futures::{self, Future}; use futures::{self, Future};
use hyper;
use hyper::header::ContentType; use hyper::header::ContentType;
use hyper::server::*; use hyper::server::*;

View file

@ -1,5 +1,5 @@
use futures::{self, Future}; use futures::{self, Future};
use hyper;
use hyper::header::Location; use hyper::header::Location;
use hyper::server::*; use hyper::server::*;

View file

@ -4,7 +4,7 @@
use std::fmt; use std::fmt;
use futures::{self, Future}; use futures::{self, Future};
use hyper;
use hyper::header::{Accept, ContentType, Server}; use hyper::header::{Accept, ContentType, Server};
use hyper::mime; use hyper::mime;
use hyper::server::*; use hyper::server::*;
@ -118,12 +118,12 @@ impl Site {
} }
fn root_base_from_request_uri(path: &str) -> Option<String> { fn root_base_from_request_uri(path: &str) -> Option<String> {
assert!(path.starts_with("/")); assert!(path.starts_with('/'));
let slashes = path[1..].matches('/').count(); let slashes = path[1..].matches('/').count();
match slashes { match slashes {
0 => None, 0 => None,
n => Some(::std::iter::repeat("../").take(n).collect()), n => Some("../".repeat(n)),
} }
} }
@ -143,10 +143,7 @@ impl Service for Site {
false => None, false => None,
}; };
let accept_header = headers let accept_header = headers.get().cloned().unwrap_or(Accept(vec![]));
.get()
.map(|x: &Accept| x.clone())
.unwrap_or(Accept(vec![]));
let base = root_base_from_request_uri(uri.path()); let base = root_base_from_request_uri(uri.path());
let base2 = base.clone(); // Bah, stupid clone let base2 = base.clone(); // Bah, stupid clone
@ -167,16 +164,9 @@ impl Service for Site {
_ => Box::new(futures::finished(resource.method_not_allowed())), _ => Box::new(futures::finished(resource.method_not_allowed())),
} }
} }
None => Box::new(futures::finished(Self::not_found( None => Box::new(futures::finished(Self::not_found(base.as_deref()))),
base.as_ref().map(|x| &**x),
))),
})
.or_else(move |err| {
Ok(Self::internal_server_error(
base2.as_ref().map(|x| &**x),
err,
))
}) })
.or_else(move |err| Ok(Self::internal_server_error(base2.as_deref(), err)))
.map(|response| response.with_header(SERVER.clone())), .map(|response| response.with_header(SERVER.clone())),
) )
} }

View file

@ -1,6 +1,3 @@
use std;
use diesel;
use diesel::prelude::*; use diesel::prelude::*;
use diesel::sqlite::SqliteConnection; use diesel::sqlite::SqliteConnection;
use futures_cpupool::{self, CpuFuture}; use futures_cpupool::{self, CpuFuture};
@ -72,7 +69,7 @@ fn decide_slug(
let base_slug = ::slug::slugify(title); let base_slug = ::slug::slugify(title);
if let Some(prev_slug) = prev_slug { if let Some(prev_slug) = prev_slug {
if prev_slug == "" { if prev_slug.is_empty() {
// Never give a non-empty slug to the front page // Never give a non-empty slug to the front page
return Ok(String::new()); return Ok(String::new());
} }
@ -313,7 +310,7 @@ impl<'a> SyncState<'a> {
theme: Option<Theme>, theme: Option<Theme>,
) -> Result<UpdateResult, Error> { ) -> Result<UpdateResult, Error> {
if title.is_empty() { if title.is_empty() {
Err("title cannot be empty")?; return Err("title cannot be empty".into());
} }
self.db_connection.transaction(|| { self.db_connection.transaction(|| {
@ -332,7 +329,7 @@ impl<'a> SyncState<'a> {
// This scheme would make POST idempotent. // This scheme would make POST idempotent.
if base_revision > latest_revision { if base_revision > latest_revision {
Err("This edit is based on a future version of the article")?; return Err("This edit is based on a future version of the article".into());
} }
let theme = theme.unwrap_or(prev_theme); let theme = theme.unwrap_or(prev_theme);
@ -375,7 +372,7 @@ impl<'a> SyncState<'a> {
slug: &slug, slug: &slug,
title: &title, title: &title,
body: &body, body: &body,
author: author.as_ref().map(|x| &**x), author: author.as_deref(),
latest: true, latest: true,
theme, theme,
}) })
@ -399,7 +396,7 @@ impl<'a> SyncState<'a> {
theme: Theme, theme: Theme,
) -> Result<models::ArticleRevision, Error> { ) -> Result<models::ArticleRevision, Error> {
if title.is_empty() { if title.is_empty() {
Err("title cannot be empty")?; return Err("title cannot be empty".into());
} }
self.db_connection.transaction(|| { self.db_connection.transaction(|| {
@ -425,7 +422,7 @@ impl<'a> SyncState<'a> {
article_id, article_id,
"", "",
&title, &title,
target_slug.as_ref().map(|x| &**x), target_slug.as_deref(),
)?; )?;
let new_revision = 1; let new_revision = 1;
@ -437,7 +434,7 @@ impl<'a> SyncState<'a> {
slug: &slug, slug: &slug,
title: &title, title: &title,
body: &body, body: &body,
author: author.as_ref().map(|x| &**x), author: author.as_deref(),
latest: true, latest: true,
theme, theme,
}) })
@ -705,7 +702,7 @@ mod test {
.update_article( .update_article(
article.article_id, article.article_id,
first_edit.revision, first_edit.revision,
article.title.clone(), article.title,
"Newer body".into(), "Newer body".into(),
None, None,
Some(Theme::Amber), Some(Theme::Amber),
@ -891,7 +888,7 @@ mod test {
theme, theme,
}) => { }) => {
assert_eq!(first_edit.revision, base_article.revision); assert_eq!(first_edit.revision, base_article.revision);
assert_eq!(title, merge::MergeResult::Clean(article.title.clone())); assert_eq!(title, merge::MergeResult::Clean(article.title));
assert_eq!( assert_eq!(
body, body,
merge::MergeResult::Conflicted(vec![merge::Output::Conflict( merge::MergeResult::Conflicted(vec![merge::Output::Conflict(
@ -929,7 +926,7 @@ mod test {
.update_article( .update_article(
article.article_id, article.article_id,
article.revision, article.revision,
article.title.clone(), article.title,
"a\nb\ny\nc\n".into(), "a\nb\ny\nc\n".into(),
None, None,
Some(Theme::Cyan), Some(Theme::Cyan),

View file

@ -5,8 +5,6 @@ use diesel::deserialize::{self, FromSql};
use diesel::serialize::{self, Output, ToSql}; use diesel::serialize::{self, Output, ToSql};
use diesel::sql_types::Text; use diesel::sql_types::Text;
use diesel::sqlite::Sqlite; use diesel::sqlite::Sqlite;
use rand;
use seahash;
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)] // Serde #[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)] // Serde
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
@ -97,9 +95,6 @@ mod test {
use diesel::prelude::*; use diesel::prelude::*;
use diesel::sql_query; use diesel::sql_query;
use diesel::sql_types::Text; use diesel::sql_types::Text;
use serde_json;
use serde_plain;
use serde_urlencoded;
use super::*; use super::*;

View file

@ -1,5 +1,3 @@
use futures;
pub trait Lookup { pub trait Lookup {
type Resource; type Resource;
type Error; type Error;

View file

@ -1,8 +1,6 @@
use futures;
use futures::{Future, Stream}; use futures::{Future, Stream};
use hyper::server::Response; use hyper::server::Response;
use hyper::{self, header, mime, server}; use hyper::{self, header, mime, server};
use std;
lazy_static! { lazy_static! {
static ref TEXT_PLAIN: mime::Mime = "text/plain;charset=utf-8".parse().unwrap(); static ref TEXT_PLAIN: mime::Mime = "text/plain;charset=utf-8".parse().unwrap();

View file

@ -81,7 +81,7 @@ fn fs_lookup(
use std::fs::File; use std::fs::File;
use std::io::prelude::*; use std::io::prelude::*;
let extension = path.rsplitn(2, ".").next(); let extension = path.rsplit_once('.').map(|x| x.1);
let content_type = match extension { let content_type = match extension {
Some("html") => "text/html", Some("html") => "text/html",
@ -263,10 +263,10 @@ impl Lookup for WikiLookup {
type Future = Box<dyn Future<Item = Option<Self::Resource>, Error = Self::Error>>; type Future = Box<dyn Future<Item = Option<Self::Resource>, Error = Self::Error>>;
fn lookup(&self, path: &str, query: Option<&str>) -> Self::Future { fn lookup(&self, path: &str, query: Option<&str>) -> Self::Future {
assert!(path.starts_with("/")); assert!(path.starts_with('/'));
let path = &path[1..]; let path = &path[1..];
if path.starts_with("_") { if path.starts_with('_') {
self.reserved_lookup(path, query) self.reserved_lookup(path, query)
} else { } else {
self.article_lookup(path, query) self.article_lookup(path, query)