diff --git a/Cargo.toml b/Cargo.toml index e8ba98c..d4df0b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ description = "A wiki engine" license = "GPL-3.0" name = "sausagewiki" version = "0.1.0-dev" +edition = "2018" [build-dependencies] quote = "0.3.10" diff --git a/src/assets.rs b/src/assets.rs index db22910..4da677d 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -2,7 +2,7 @@ mod static_assets { use std::collections::HashMap; use futures::Future; - use web::{Resource, ResponseFuture}; + use crate::web::{Resource, ResponseFuture}; // The CSS should be built to a single CSS file at compile time #[derive(StaticResource)] @@ -32,8 +32,8 @@ mod static_assets { // #[mime = "application/font-woff"] // pub struct AmaticFont; - type BoxResource = Box; - type ResourceFn = Box BoxResource + Sync + Send>; + type BoxResource = Box; + type ResourceFn = Box BoxResource + Sync + Send>; lazy_static! { pub static ref ASSETS_MAP: HashMap<&'static str, ResourceFn> = hashmap!{ // The CSS should be built to a single CSS file at compile time diff --git a/src/db.rs b/src/db.rs index 5308191..aaf2bf3 100644 --- a/src/db.rs +++ b/src/db.rs @@ -4,8 +4,8 @@ use diesel::sql_types::*; use r2d2::{CustomizeConnection, Pool}; use r2d2_diesel::{self, ConnectionManager}; -use rendering; -use theme; +use crate::rendering; +use crate::theme; embed_migrations!(); @@ -39,7 +39,7 @@ impl CustomizeConnection for SqliteInitial } } -pub fn create_pool>(connection_string: S) -> Result>, Box<::std::error::Error>> { +pub fn create_pool>(connection_string: S) -> Result>, Box> { let manager = ConnectionManager::::new(connection_string); let pool = Pool::builder() .connection_customizer(Box::new(SqliteInitializer {})) diff --git a/src/lib.rs b/src/lib.rs index e1a63d2..f285ea5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,7 +52,7 @@ mod theme; mod web; mod wiki_lookup; -pub fn main(db_file: String, bind_host: IpAddr, bind_port: u16, trust_identity: bool) -> Result<(), Box> { +pub fn main(db_file: String, bind_host: IpAddr, bind_port: u16, trust_identity: bool) -> Result<(), Box> { let db_pool = db::create_pool(db_file)?; let cpu_pool = futures_cpupool::CpuPool::new_num_cpus(); diff --git a/src/main.rs b/src/main.rs index 37bb549..b6e0937 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ extern crate sausagewiki; use std::net::IpAddr; mod build_config; -use build_config::*; +use crate::build_config::*; const DATABASE: &str = "DATABASE"; const TRUST_IDENTITY: &str = "trust-identity"; @@ -49,7 +49,7 @@ fn args<'a>() -> clap::ArgMatches<'a> { .get_matches() } -fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { let args = args(); const CLAP: &str = "Guaranteed by clap"; diff --git a/src/models.rs b/src/models.rs index 35a3148..d592f58 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,6 +1,6 @@ use chrono; -use theme::Theme; +use crate::theme::Theme; fn slug_link(slug: &str) -> &str { if slug.is_empty() { diff --git a/src/resources/about_resource.rs b/src/resources/about_resource.rs index 711cfcd..5d08d78 100644 --- a/src/resources/about_resource.rs +++ b/src/resources/about_resource.rs @@ -3,10 +3,10 @@ use hyper; use hyper::header::ContentType; use hyper::server::*; -use build_config; -use mimes::*; -use site::system_page; -use web::{Resource, ResponseFuture}; +use crate::build_config; +use crate::mimes::*; +use crate::site::system_page; +use crate::web::{Resource, ResponseFuture}; #[derive(Licenses)] pub struct AboutResource; diff --git a/src/resources/article_resource.rs b/src/resources/article_resource.rs index 7f274e4..3f48c11 100644 --- a/src/resources/article_resource.rs +++ b/src/resources/article_resource.rs @@ -6,13 +6,13 @@ use hyper::server::*; use serde_json; use serde_urlencoded; -use assets::ScriptJs; -use mimes::*; -use rendering::render_markdown; -use site::Layout; -use state::{State, UpdateResult, RebaseConflict}; -use theme::{self, Theme}; -use web::{Resource, ResponseFuture}; +use crate::assets::ScriptJs; +use crate::mimes::*; +use crate::rendering::render_markdown; +use crate::site::Layout; +use crate::state::{State, UpdateResult, RebaseConflict}; +use crate::theme::{self, Theme}; +use crate::web::{Resource, ResponseFuture}; use super::changes_resource::QueryParameters; diff --git a/src/resources/article_revision_resource.rs b/src/resources/article_revision_resource.rs index 1e5da96..ab1367d 100644 --- a/src/resources/article_revision_resource.rs +++ b/src/resources/article_revision_resource.rs @@ -4,11 +4,11 @@ use hyper; use hyper::header::ContentType; use hyper::server::*; -use mimes::*; -use models; -use rendering::render_markdown; -use site::system_page; -use web::{Resource, ResponseFuture}; +use crate::mimes::*; +use crate::models; +use crate::rendering::render_markdown; +use crate::site::system_page; +use crate::web::{Resource, ResponseFuture}; use super::changes_resource::QueryParameters; use super::diff_resource; diff --git a/src/resources/changes_resource.rs b/src/resources/changes_resource.rs index af677af..18c7d83 100644 --- a/src/resources/changes_resource.rs +++ b/src/resources/changes_resource.rs @@ -6,11 +6,11 @@ use hyper::header::ContentType; use hyper::server::*; use serde_urlencoded; -use mimes::*; -use schema::article_revisions; -use site::system_page; -use state::State; -use web::{Resource, ResponseFuture}; +use crate::mimes::*; +use crate::schema::article_revisions; +use crate::site::system_page; +use crate::state::State; +use crate::web::{Resource, ResponseFuture}; use super::diff_resource; use super::pagination::Pagination; @@ -18,7 +18,7 @@ use super::TemporaryRedirectResource; const DEFAULT_LIMIT: i32 = 30; -type BoxResource = Box; +type BoxResource = Box; #[derive(Clone)] pub struct ChangesLookup { @@ -97,7 +97,7 @@ impl ChangesLookup { Self { state, show_authors } } - pub fn lookup(&self, query: Option<&str>) -> Box, Error=::web::Error>> { + pub fn lookup(&self, query: Option<&str>) -> Box, Error=crate::web::Error>> { use super::pagination; let state = self.state.clone(); @@ -154,7 +154,7 @@ impl ChangesLookup { args.into_link() )) as BoxResource, })) - })) as Box, Error=::web::Error>> + })) as Box, Error=crate::web::Error>> }, Pagination::Before(x) => Box::new(finished(Some(Box::new(ChangesResource::new(state, show_authors, Some(x), article_id, author, limit)) as BoxResource))), Pagination::None => Box::new(finished(Some(Box::new(ChangesResource::new(state, show_authors, None, article_id, author, limit)) as BoxResource))), diff --git a/src/resources/diff_resource.rs b/src/resources/diff_resource.rs index 7088a74..2211af3 100644 --- a/src/resources/diff_resource.rs +++ b/src/resources/diff_resource.rs @@ -8,17 +8,17 @@ use hyper::header::ContentType; use hyper::server::*; use serde_urlencoded; -use mimes::*; -use models::ArticleRevision; -use site::Layout; -use state::State; -use theme; -use web::{Resource, ResponseFuture}; +use crate::mimes::*; +use crate::models::ArticleRevision; +use crate::site::Layout; +use crate::state::State; +use crate::theme; +use crate::web::{Resource, ResponseFuture}; use super::changes_resource; use super::pagination::Pagination; -type BoxResource = Box; +type BoxResource = Box; #[derive(Clone)] pub struct DiffLookup { @@ -48,7 +48,7 @@ impl DiffLookup { Self { state } } - pub fn lookup(&self, article_id: u32, query: Option<&str>) -> Box, Error=::web::Error>> { + pub fn lookup(&self, article_id: u32, query: Option<&str>) -> Box, Error=crate::web::Error>> { let state = self.state.clone(); Box::new(done( diff --git a/src/resources/html_resource.rs b/src/resources/html_resource.rs index b1fcaa9..0811949 100644 --- a/src/resources/html_resource.rs +++ b/src/resources/html_resource.rs @@ -3,9 +3,9 @@ use hyper; use hyper::header::ContentType; use hyper::server::*; -use mimes::*; -use site::system_page; -use web::{Resource, ResponseFuture}; +use crate::mimes::*; +use crate::site::system_page; +use crate::web::{Resource, ResponseFuture}; pub struct HtmlResource { base: Option<&'static str>, diff --git a/src/resources/new_article_resource.rs b/src/resources/new_article_resource.rs index 5cb0a30..b3e7950 100644 --- a/src/resources/new_article_resource.rs +++ b/src/resources/new_article_resource.rs @@ -5,13 +5,13 @@ use hyper::server::*; use serde_json; use serde_urlencoded; -use assets::ScriptJs; -use mimes::*; -use rendering::render_markdown; -use site::Layout; -use state::State; -use theme::{self, Theme}; -use web::{Resource, ResponseFuture}; +use crate::assets::ScriptJs; +use crate::mimes::*; +use crate::rendering::render_markdown; +use crate::site::Layout; +use crate::state::State; +use crate::theme::{self, Theme}; +use crate::web::{Resource, ResponseFuture}; const NEW: &str = "NEW"; diff --git a/src/resources/pagination.rs b/src/resources/pagination.rs index 9b7b4a6..7b03088 100644 --- a/src/resources/pagination.rs +++ b/src/resources/pagination.rs @@ -8,7 +8,7 @@ pub struct Error; impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - write!(f, "{}", (self as &error::Error).description()) + write!(f, "{}", (self as &dyn error::Error).description()) } } diff --git a/src/resources/read_only_resource.rs b/src/resources/read_only_resource.rs index 9ad2e65..77476b5 100644 --- a/src/resources/read_only_resource.rs +++ b/src/resources/read_only_resource.rs @@ -3,7 +3,7 @@ use hyper::header::{ContentType, ContentLength, CacheControl, CacheDirective}; use hyper::server::*; use hyper::StatusCode; -use web::{Resource, ResponseFuture}; +use crate::web::{Resource, ResponseFuture}; #[allow(unused)] pub struct ReadOnlyResource { diff --git a/src/resources/search_resource.rs b/src/resources/search_resource.rs index 3ce024f..5f65517 100644 --- a/src/resources/search_resource.rs +++ b/src/resources/search_resource.rs @@ -5,16 +5,16 @@ use hyper::server::*; use serde_json; use serde_urlencoded; -use mimes::*; -use models::SearchResult; -use site::system_page; -use state::State; -use web::{Resource, ResponseFuture}; +use crate::mimes::*; +use crate::models::SearchResult; +use crate::site::system_page; +use crate::state::State; +use crate::web::{Resource, ResponseFuture}; const DEFAULT_LIMIT: u32 = 10; const DEFAULT_SNIPPET_SIZE: u32 = 30; -type BoxResource = Box; +type BoxResource = Box; #[derive(Serialize, Deserialize, Default)] pub struct QueryParameters { @@ -66,7 +66,7 @@ impl SearchLookup { Self { state } } - pub fn lookup(&self, query: Option<&str>) -> Result, ::web::Error> { + pub fn lookup(&self, query: Option<&str>) -> Result, crate::web::Error> { let args: QueryParameters = serde_urlencoded::from_str(query.unwrap_or(""))?; Ok(Some(Box::new( diff --git a/src/resources/sitemap_resource.rs b/src/resources/sitemap_resource.rs index 448b633..0984c88 100644 --- a/src/resources/sitemap_resource.rs +++ b/src/resources/sitemap_resource.rs @@ -3,11 +3,11 @@ use hyper; use hyper::header::ContentType; use hyper::server::*; -use mimes::*; -use models::ArticleRevisionStub; -use site::system_page; -use state::State; -use web::{Resource, ResponseFuture}; +use crate::mimes::*; +use crate::models::ArticleRevisionStub; +use crate::site::system_page; +use crate::state::State; +use crate::web::{Resource, ResponseFuture}; pub struct SitemapResource { state: State, diff --git a/src/resources/temporary_redirect_resource.rs b/src/resources/temporary_redirect_resource.rs index e9331d2..7130567 100644 --- a/src/resources/temporary_redirect_resource.rs +++ b/src/resources/temporary_redirect_resource.rs @@ -3,7 +3,7 @@ use hyper; use hyper::header::Location; use hyper::server::*; -use web::{Resource, ResponseFuture}; +use crate::web::{Resource, ResponseFuture}; pub struct TemporaryRedirectResource { location: String, diff --git a/src/site.rs b/src/site.rs index fc71b14..37e9ee9 100644 --- a/src/site.rs +++ b/src/site.rs @@ -9,11 +9,11 @@ use hyper::mime; use hyper::server::*; use hyper; -use assets::{ThemesCss, StyleCss, SearchJs}; -use build_config; -use theme; -use web::Lookup; -use wiki_lookup::WikiLookup; +use crate::assets::{ThemesCss, StyleCss, SearchJs}; +use crate::build_config; +use crate::theme; +use crate::web::Lookup; +use crate::wiki_lookup::WikiLookup; lazy_static! { static ref TEXT_HTML: mime::Mime = "text/html;charset=utf-8".parse().unwrap(); @@ -93,7 +93,7 @@ impl Site { .with_status(hyper::StatusCode::NotFound) } - fn internal_server_error(base: Option<&str>, err: Box<::std::error::Error + Send + Sync>) -> Response { + fn internal_server_error(base: Option<&str>, err: Box) -> Response { eprintln!("Internal Server Error:\n{:#?}", err); Response::new() @@ -121,7 +121,7 @@ impl Service for Site { type Request = Request; type Response = Response; type Error = hyper::Error; - type Future = Box>; + type Future = Box>; fn call(&self, req: Request) -> Self::Future { let (method, uri, _http_version, headers, body) = req.deconstruct(); diff --git a/src/state.rs b/src/state.rs index faeb565..51c319c 100644 --- a/src/state.rs +++ b/src/state.rs @@ -7,10 +7,10 @@ use futures_cpupool::{self, CpuFuture}; use r2d2::Pool; use r2d2_diesel::ConnectionManager; -use merge; -use models; -use schema::*; -use theme::Theme; +use crate::merge; +use crate::models; +use crate::schema::*; +use crate::theme::Theme; #[derive(Clone)] pub struct State { @@ -18,7 +18,7 @@ pub struct State { cpu_pool: futures_cpupool::CpuPool, } -pub type Error = Box; +pub type Error = Box; pub enum SlugLookup { Miss, @@ -81,7 +81,7 @@ fn decide_slug(conn: &SqliteConnection, article_id: i32, prev_title: &str, title let base_slug = if base_slug.is_empty() { "article" } else { &base_slug }; - use schema::article_revisions; + use crate::schema::article_revisions; let mut slug = base_slug.to_owned(); let mut disambiguator = 1; @@ -113,7 +113,7 @@ impl<'a> SyncState<'a> { } pub fn get_article_slug(&self, article_id: i32) -> Result, Error> { - use schema::article_revisions; + use crate::schema::article_revisions; Ok(article_revisions::table .filter(article_revisions::article_id.eq(article_id)) @@ -124,7 +124,7 @@ impl<'a> SyncState<'a> { } pub fn get_article_revision(&self, article_id: i32, revision: i32) -> Result, Error> { - use schema::article_revisions; + use crate::schema::article_revisions; Ok(article_revisions::table .filter(article_revisions::article_id.eq(article_id)) @@ -140,7 +140,7 @@ impl<'a> SyncState<'a> { FnOnce(article_revisions::BoxedQuery<'x, diesel::sqlite::Sqlite>) -> article_revisions::BoxedQuery<'x, diesel::sqlite::Sqlite>, { - use schema::article_revisions::dsl::*; + use crate::schema::article_revisions::dsl::*; Ok(f(article_revisions.into_boxed()) .select(( @@ -159,7 +159,7 @@ impl<'a> SyncState<'a> { } fn get_article_revision_stub(&self, article_id: i32, revision: i32) -> Result, Error> { - use schema::article_revisions; + use crate::schema::article_revisions; Ok(self.query_article_revision_stubs(move |query| { query @@ -178,7 +178,7 @@ impl<'a> SyncState<'a> { } self.db_connection.transaction(|| { - use schema::article_revisions; + use crate::schema::article_revisions; Ok(match article_revisions::table .filter(article_revisions::slug.eq(slug)) @@ -238,7 +238,7 @@ impl<'a> SyncState<'a> { let (title_b, body_b, theme_b) = stored.pop().expect("Application layer guarantee"); let (title_o, body_o, theme_o) = stored.pop().expect("Application layer guarantee"); - use merge::MergeResult::*; + use crate::merge::MergeResult::*; fn merge_themes(a: Theme, o: Theme, b: Theme) -> Theme { // Last change wins @@ -279,7 +279,7 @@ impl<'a> SyncState<'a> { } self.db_connection.transaction(|| { - use schema::article_revisions; + use crate::schema::article_revisions; let (latest_revision, prev_title, prev_slug, prev_theme) = article_revisions::table .filter(article_revisions::article_id.eq(article_id)) @@ -499,7 +499,7 @@ impl State { #[cfg(test)] mod test { use super::*; - use db; + use crate::db; impl UpdateResult { pub fn unwrap(self) -> models::ArticleRevision { diff --git a/src/theme.rs b/src/theme.rs index 19604b4..1d9a053 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -188,7 +188,7 @@ mod test { } #[test] - fn basic_db_roundtrip() -> Result<(), Box> { + fn basic_db_roundtrip() -> Result<(), Box> { let conn = SqliteConnection::establish(":memory:")?; #[derive(QueryableByName, PartialEq, Eq, Debug)] @@ -204,7 +204,7 @@ mod test { } #[test] - fn db_invalid_value_gives_error() -> Result<(), Box> { + fn db_invalid_value_gives_error() -> Result<(), Box> { let conn = SqliteConnection::establish(":memory:")?; #[derive(QueryableByName, PartialEq, Eq, Debug)] diff --git a/src/web/resource.rs b/src/web/resource.rs index 9af2436..23730ba 100644 --- a/src/web/resource.rs +++ b/src/web/resource.rs @@ -8,8 +8,8 @@ lazy_static! { static ref TEXT_PLAIN: mime::Mime = "text/plain;charset=utf-8".parse().unwrap(); } -pub type Error = Box; -pub type ResponseFuture = Box>; +pub type Error = Box; +pub type ResponseFuture = Box>; pub trait Resource { fn allow(&self) -> Vec; diff --git a/src/wiki_lookup.rs b/src/wiki_lookup.rs index fe84a39..ac5e503 100644 --- a/src/wiki_lookup.rs +++ b/src/wiki_lookup.rs @@ -7,15 +7,15 @@ use futures::future::FutureResult; use percent_encoding::percent_decode; use slug::slugify; -use resources::*; -use state::State; -use web::{Lookup, Resource}; +use crate::resources::*; +use crate::state::State; +use crate::web::{Lookup, Resource}; #[allow(unused)] -use assets::*; +use crate::assets::*; -type BoxResource = Box; -type ResourceFn = Box BoxResource + Sync + Send>; +type BoxResource = Box; +type ResourceFn = Box BoxResource + Sync + Send>; lazy_static! { static ref LICENSES_MAP: HashMap<&'static str, ResourceFn> = hashmap!{ @@ -55,7 +55,7 @@ fn split_one(path: &str) -> Result<(Cow, Option<&str>), Utf8Error> { } fn map_lookup(map: &HashMap<&str, ResourceFn>, path: &str) -> - FutureResult, Box<::std::error::Error + Send + Sync>> + FutureResult, Box> { let (head, tail) = match split_one(path) { Ok(x) => x, @@ -74,7 +74,7 @@ fn map_lookup(map: &HashMap<&str, ResourceFn>, path: &str) -> #[allow(unused)] fn fs_lookup(root: &str, path: &str) -> - FutureResult, Box<::std::error::Error + Send + Sync>> + FutureResult, Box> { use std::fs::File; use std::io::prelude::*; @@ -93,7 +93,7 @@ fn fs_lookup(root: &str, path: &str) -> filename.push_str(path); let mut f = File::open(&filename) - .unwrap_or_else(|_| panic!(format!("Not found: {}", filename))); + .unwrap_or_else(|_| panic!("Not found: {}", filename)); let mut body = Vec::new(); f.read_to_end(&mut body) @@ -233,7 +233,7 @@ impl WikiLookup { let state = self.state.clone(); let slug = slug.into_owned(); - use state::SlugLookup; + use crate::state::SlugLookup; Box::new(self.state.lookup_slug(slug.clone()) .and_then(move |x| Ok(Some(match x { SlugLookup::Miss => @@ -249,8 +249,8 @@ impl WikiLookup { impl Lookup for WikiLookup { type Resource = BoxResource; - type Error = Box<::std::error::Error + Send + Sync>; - type Future = Box, Error = Self::Error>>; + type Error = Box; + type Future = Box, Error = Self::Error>>; fn lookup(&self, path: &str, query: Option<&str>) -> Self::Future { assert!(path.starts_with("/"));