Update edition, cargo fix and cargo fix --edition
This commit is contained in:
parent
3f71040aec
commit
26fe2b64da
23 changed files with 105 additions and 104 deletions
|
@ -4,6 +4,7 @@ description = "A wiki engine"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
name = "sausagewiki"
|
name = "sausagewiki"
|
||||||
version = "0.1.0-dev"
|
version = "0.1.0-dev"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
quote = "0.3.10"
|
quote = "0.3.10"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
mod static_assets {
|
mod static_assets {
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use futures::Future;
|
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
|
// The CSS should be built to a single CSS file at compile time
|
||||||
#[derive(StaticResource)]
|
#[derive(StaticResource)]
|
||||||
|
@ -32,8 +32,8 @@ mod static_assets {
|
||||||
// #[mime = "application/font-woff"]
|
// #[mime = "application/font-woff"]
|
||||||
// pub struct AmaticFont;
|
// pub struct AmaticFont;
|
||||||
|
|
||||||
type BoxResource = Box<Resource + Sync + Send>;
|
type BoxResource = Box<dyn Resource + Sync + Send>;
|
||||||
type ResourceFn = Box<Fn() -> BoxResource + Sync + Send>;
|
type ResourceFn = Box<dyn Fn() -> BoxResource + Sync + Send>;
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref ASSETS_MAP: HashMap<&'static str, ResourceFn> = hashmap!{
|
pub static ref ASSETS_MAP: HashMap<&'static str, ResourceFn> = hashmap!{
|
||||||
// The CSS should be built to a single CSS file at compile time
|
// The CSS should be built to a single CSS file at compile time
|
||||||
|
|
|
@ -4,8 +4,8 @@ use diesel::sql_types::*;
|
||||||
use r2d2::{CustomizeConnection, Pool};
|
use r2d2::{CustomizeConnection, Pool};
|
||||||
use r2d2_diesel::{self, ConnectionManager};
|
use r2d2_diesel::{self, ConnectionManager};
|
||||||
|
|
||||||
use rendering;
|
use crate::rendering;
|
||||||
use theme;
|
use crate::theme;
|
||||||
|
|
||||||
embed_migrations!();
|
embed_migrations!();
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ impl CustomizeConnection<SqliteConnection, r2d2_diesel::Error> for SqliteInitial
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_pool<S: Into<String>>(connection_string: S) -> Result<Pool<ConnectionManager<SqliteConnection>>, Box<::std::error::Error>> {
|
pub fn create_pool<S: Into<String>>(connection_string: S) -> Result<Pool<ConnectionManager<SqliteConnection>>, Box<dyn (::std::error::Error)>> {
|
||||||
let manager = ConnectionManager::<SqliteConnection>::new(connection_string);
|
let manager = ConnectionManager::<SqliteConnection>::new(connection_string);
|
||||||
let pool = Pool::builder()
|
let pool = Pool::builder()
|
||||||
.connection_customizer(Box::new(SqliteInitializer {}))
|
.connection_customizer(Box::new(SqliteInitializer {}))
|
||||||
|
|
|
@ -52,7 +52,7 @@ mod theme;
|
||||||
mod web;
|
mod web;
|
||||||
mod wiki_lookup;
|
mod wiki_lookup;
|
||||||
|
|
||||||
pub fn main(db_file: String, bind_host: IpAddr, bind_port: u16, trust_identity: bool) -> Result<(), Box<std::error::Error>> {
|
pub fn main(db_file: String, bind_host: IpAddr, bind_port: u16, trust_identity: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let db_pool = db::create_pool(db_file)?;
|
let db_pool = db::create_pool(db_file)?;
|
||||||
let cpu_pool = futures_cpupool::CpuPool::new_num_cpus();
|
let cpu_pool = futures_cpupool::CpuPool::new_num_cpus();
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ extern crate sausagewiki;
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
|
|
||||||
mod build_config;
|
mod build_config;
|
||||||
use build_config::*;
|
use crate::build_config::*;
|
||||||
|
|
||||||
const DATABASE: &str = "DATABASE";
|
const DATABASE: &str = "DATABASE";
|
||||||
const TRUST_IDENTITY: &str = "trust-identity";
|
const TRUST_IDENTITY: &str = "trust-identity";
|
||||||
|
@ -49,7 +49,7 @@ fn args<'a>() -> clap::ArgMatches<'a> {
|
||||||
.get_matches()
|
.get_matches()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let args = args();
|
let args = args();
|
||||||
|
|
||||||
const CLAP: &str = "Guaranteed by clap";
|
const CLAP: &str = "Guaranteed by clap";
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use chrono;
|
use chrono;
|
||||||
|
|
||||||
use theme::Theme;
|
use crate::theme::Theme;
|
||||||
|
|
||||||
fn slug_link(slug: &str) -> &str {
|
fn slug_link(slug: &str) -> &str {
|
||||||
if slug.is_empty() {
|
if slug.is_empty() {
|
||||||
|
|
|
@ -3,10 +3,10 @@ use hyper;
|
||||||
use hyper::header::ContentType;
|
use hyper::header::ContentType;
|
||||||
use hyper::server::*;
|
use hyper::server::*;
|
||||||
|
|
||||||
use build_config;
|
use crate::build_config;
|
||||||
use mimes::*;
|
use crate::mimes::*;
|
||||||
use site::system_page;
|
use crate::site::system_page;
|
||||||
use web::{Resource, ResponseFuture};
|
use crate::web::{Resource, ResponseFuture};
|
||||||
|
|
||||||
#[derive(Licenses)]
|
#[derive(Licenses)]
|
||||||
pub struct AboutResource;
|
pub struct AboutResource;
|
||||||
|
|
|
@ -6,13 +6,13 @@ use hyper::server::*;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use serde_urlencoded;
|
use serde_urlencoded;
|
||||||
|
|
||||||
use assets::ScriptJs;
|
use crate::assets::ScriptJs;
|
||||||
use mimes::*;
|
use crate::mimes::*;
|
||||||
use rendering::render_markdown;
|
use crate::rendering::render_markdown;
|
||||||
use site::Layout;
|
use crate::site::Layout;
|
||||||
use state::{State, UpdateResult, RebaseConflict};
|
use crate::state::{State, UpdateResult, RebaseConflict};
|
||||||
use theme::{self, Theme};
|
use crate::theme::{self, Theme};
|
||||||
use web::{Resource, ResponseFuture};
|
use crate::web::{Resource, ResponseFuture};
|
||||||
|
|
||||||
use super::changes_resource::QueryParameters;
|
use super::changes_resource::QueryParameters;
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,11 @@ use hyper;
|
||||||
use hyper::header::ContentType;
|
use hyper::header::ContentType;
|
||||||
use hyper::server::*;
|
use hyper::server::*;
|
||||||
|
|
||||||
use mimes::*;
|
use crate::mimes::*;
|
||||||
use models;
|
use crate::models;
|
||||||
use rendering::render_markdown;
|
use crate::rendering::render_markdown;
|
||||||
use site::system_page;
|
use crate::site::system_page;
|
||||||
use web::{Resource, ResponseFuture};
|
use crate::web::{Resource, ResponseFuture};
|
||||||
|
|
||||||
use super::changes_resource::QueryParameters;
|
use super::changes_resource::QueryParameters;
|
||||||
use super::diff_resource;
|
use super::diff_resource;
|
||||||
|
|
|
@ -6,11 +6,11 @@ use hyper::header::ContentType;
|
||||||
use hyper::server::*;
|
use hyper::server::*;
|
||||||
use serde_urlencoded;
|
use serde_urlencoded;
|
||||||
|
|
||||||
use mimes::*;
|
use crate::mimes::*;
|
||||||
use schema::article_revisions;
|
use crate::schema::article_revisions;
|
||||||
use site::system_page;
|
use crate::site::system_page;
|
||||||
use state::State;
|
use crate::state::State;
|
||||||
use web::{Resource, ResponseFuture};
|
use crate::web::{Resource, ResponseFuture};
|
||||||
|
|
||||||
use super::diff_resource;
|
use super::diff_resource;
|
||||||
use super::pagination::Pagination;
|
use super::pagination::Pagination;
|
||||||
|
@ -18,7 +18,7 @@ use super::TemporaryRedirectResource;
|
||||||
|
|
||||||
const DEFAULT_LIMIT: i32 = 30;
|
const DEFAULT_LIMIT: i32 = 30;
|
||||||
|
|
||||||
type BoxResource = Box<Resource + Sync + Send>;
|
type BoxResource = Box<dyn Resource + Sync + Send>;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ChangesLookup {
|
pub struct ChangesLookup {
|
||||||
|
@ -97,7 +97,7 @@ impl ChangesLookup {
|
||||||
Self { state, show_authors }
|
Self { state, show_authors }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lookup(&self, query: Option<&str>) -> Box<Future<Item=Option<BoxResource>, Error=::web::Error>> {
|
pub fn lookup(&self, query: Option<&str>) -> Box<dyn Future<Item=Option<BoxResource>, Error=crate::web::Error>> {
|
||||||
use super::pagination;
|
use super::pagination;
|
||||||
|
|
||||||
let state = self.state.clone();
|
let state = self.state.clone();
|
||||||
|
@ -154,7 +154,7 @@ impl ChangesLookup {
|
||||||
args.into_link()
|
args.into_link()
|
||||||
)) as BoxResource,
|
)) as BoxResource,
|
||||||
}))
|
}))
|
||||||
})) as Box<Future<Item=Option<BoxResource>, Error=::web::Error>>
|
})) as Box<dyn Future<Item=Option<BoxResource>, 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::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))),
|
Pagination::None => Box::new(finished(Some(Box::new(ChangesResource::new(state, show_authors, None, article_id, author, limit)) as BoxResource))),
|
||||||
|
|
|
@ -8,17 +8,17 @@ use hyper::header::ContentType;
|
||||||
use hyper::server::*;
|
use hyper::server::*;
|
||||||
use serde_urlencoded;
|
use serde_urlencoded;
|
||||||
|
|
||||||
use mimes::*;
|
use crate::mimes::*;
|
||||||
use models::ArticleRevision;
|
use crate::models::ArticleRevision;
|
||||||
use site::Layout;
|
use crate::site::Layout;
|
||||||
use state::State;
|
use crate::state::State;
|
||||||
use theme;
|
use crate::theme;
|
||||||
use web::{Resource, ResponseFuture};
|
use crate::web::{Resource, ResponseFuture};
|
||||||
|
|
||||||
use super::changes_resource;
|
use super::changes_resource;
|
||||||
use super::pagination::Pagination;
|
use super::pagination::Pagination;
|
||||||
|
|
||||||
type BoxResource = Box<Resource + Sync + Send>;
|
type BoxResource = Box<dyn Resource + Sync + Send>;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct DiffLookup {
|
pub struct DiffLookup {
|
||||||
|
@ -48,7 +48,7 @@ impl DiffLookup {
|
||||||
Self { state }
|
Self { state }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lookup(&self, article_id: u32, query: Option<&str>) -> Box<Future<Item=Option<BoxResource>, Error=::web::Error>> {
|
pub fn lookup(&self, article_id: u32, query: Option<&str>) -> Box<dyn Future<Item=Option<BoxResource>, Error=crate::web::Error>> {
|
||||||
let state = self.state.clone();
|
let state = self.state.clone();
|
||||||
|
|
||||||
Box::new(done(
|
Box::new(done(
|
||||||
|
|
|
@ -3,9 +3,9 @@ use hyper;
|
||||||
use hyper::header::ContentType;
|
use hyper::header::ContentType;
|
||||||
use hyper::server::*;
|
use hyper::server::*;
|
||||||
|
|
||||||
use mimes::*;
|
use crate::mimes::*;
|
||||||
use site::system_page;
|
use crate::site::system_page;
|
||||||
use web::{Resource, ResponseFuture};
|
use crate::web::{Resource, ResponseFuture};
|
||||||
|
|
||||||
pub struct HtmlResource {
|
pub struct HtmlResource {
|
||||||
base: Option<&'static str>,
|
base: Option<&'static str>,
|
||||||
|
|
|
@ -5,13 +5,13 @@ use hyper::server::*;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use serde_urlencoded;
|
use serde_urlencoded;
|
||||||
|
|
||||||
use assets::ScriptJs;
|
use crate::assets::ScriptJs;
|
||||||
use mimes::*;
|
use crate::mimes::*;
|
||||||
use rendering::render_markdown;
|
use crate::rendering::render_markdown;
|
||||||
use site::Layout;
|
use crate::site::Layout;
|
||||||
use state::State;
|
use crate::state::State;
|
||||||
use theme::{self, Theme};
|
use crate::theme::{self, Theme};
|
||||||
use web::{Resource, ResponseFuture};
|
use crate::web::{Resource, ResponseFuture};
|
||||||
|
|
||||||
const NEW: &str = "NEW";
|
const NEW: &str = "NEW";
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ pub struct Error;
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use hyper::header::{ContentType, ContentLength, CacheControl, CacheDirective};
|
||||||
use hyper::server::*;
|
use hyper::server::*;
|
||||||
use hyper::StatusCode;
|
use hyper::StatusCode;
|
||||||
|
|
||||||
use web::{Resource, ResponseFuture};
|
use crate::web::{Resource, ResponseFuture};
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub struct ReadOnlyResource {
|
pub struct ReadOnlyResource {
|
||||||
|
|
|
@ -5,16 +5,16 @@ use hyper::server::*;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use serde_urlencoded;
|
use serde_urlencoded;
|
||||||
|
|
||||||
use mimes::*;
|
use crate::mimes::*;
|
||||||
use models::SearchResult;
|
use crate::models::SearchResult;
|
||||||
use site::system_page;
|
use crate::site::system_page;
|
||||||
use state::State;
|
use crate::state::State;
|
||||||
use web::{Resource, ResponseFuture};
|
use crate::web::{Resource, ResponseFuture};
|
||||||
|
|
||||||
const DEFAULT_LIMIT: u32 = 10;
|
const DEFAULT_LIMIT: u32 = 10;
|
||||||
const DEFAULT_SNIPPET_SIZE: u32 = 30;
|
const DEFAULT_SNIPPET_SIZE: u32 = 30;
|
||||||
|
|
||||||
type BoxResource = Box<Resource + Sync + Send>;
|
type BoxResource = Box<dyn Resource + Sync + Send>;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Default)]
|
#[derive(Serialize, Deserialize, Default)]
|
||||||
pub struct QueryParameters {
|
pub struct QueryParameters {
|
||||||
|
@ -66,7 +66,7 @@ impl SearchLookup {
|
||||||
Self { state }
|
Self { state }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lookup(&self, query: Option<&str>) -> Result<Option<BoxResource>, ::web::Error> {
|
pub fn lookup(&self, query: Option<&str>) -> Result<Option<BoxResource>, crate::web::Error> {
|
||||||
let args: QueryParameters = serde_urlencoded::from_str(query.unwrap_or(""))?;
|
let args: QueryParameters = serde_urlencoded::from_str(query.unwrap_or(""))?;
|
||||||
|
|
||||||
Ok(Some(Box::new(
|
Ok(Some(Box::new(
|
||||||
|
|
|
@ -3,11 +3,11 @@ use hyper;
|
||||||
use hyper::header::ContentType;
|
use hyper::header::ContentType;
|
||||||
use hyper::server::*;
|
use hyper::server::*;
|
||||||
|
|
||||||
use mimes::*;
|
use crate::mimes::*;
|
||||||
use models::ArticleRevisionStub;
|
use crate::models::ArticleRevisionStub;
|
||||||
use site::system_page;
|
use crate::site::system_page;
|
||||||
use state::State;
|
use crate::state::State;
|
||||||
use web::{Resource, ResponseFuture};
|
use crate::web::{Resource, ResponseFuture};
|
||||||
|
|
||||||
pub struct SitemapResource {
|
pub struct SitemapResource {
|
||||||
state: State,
|
state: State,
|
||||||
|
|
|
@ -3,7 +3,7 @@ use hyper;
|
||||||
use hyper::header::Location;
|
use hyper::header::Location;
|
||||||
use hyper::server::*;
|
use hyper::server::*;
|
||||||
|
|
||||||
use web::{Resource, ResponseFuture};
|
use crate::web::{Resource, ResponseFuture};
|
||||||
|
|
||||||
pub struct TemporaryRedirectResource {
|
pub struct TemporaryRedirectResource {
|
||||||
location: String,
|
location: String,
|
||||||
|
|
14
src/site.rs
14
src/site.rs
|
@ -9,11 +9,11 @@ use hyper::mime;
|
||||||
use hyper::server::*;
|
use hyper::server::*;
|
||||||
use hyper;
|
use hyper;
|
||||||
|
|
||||||
use assets::{ThemesCss, StyleCss, SearchJs};
|
use crate::assets::{ThemesCss, StyleCss, SearchJs};
|
||||||
use build_config;
|
use crate::build_config;
|
||||||
use theme;
|
use crate::theme;
|
||||||
use web::Lookup;
|
use crate::web::Lookup;
|
||||||
use wiki_lookup::WikiLookup;
|
use crate::wiki_lookup::WikiLookup;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref TEXT_HTML: mime::Mime = "text/html;charset=utf-8".parse().unwrap();
|
static ref TEXT_HTML: mime::Mime = "text/html;charset=utf-8".parse().unwrap();
|
||||||
|
@ -93,7 +93,7 @@ impl Site {
|
||||||
.with_status(hyper::StatusCode::NotFound)
|
.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<dyn ::std::error::Error + Send + Sync>) -> Response {
|
||||||
eprintln!("Internal Server Error:\n{:#?}", err);
|
eprintln!("Internal Server Error:\n{:#?}", err);
|
||||||
|
|
||||||
Response::new()
|
Response::new()
|
||||||
|
@ -121,7 +121,7 @@ impl Service for Site {
|
||||||
type Request = Request;
|
type Request = Request;
|
||||||
type Response = Response;
|
type Response = Response;
|
||||||
type Error = hyper::Error;
|
type Error = hyper::Error;
|
||||||
type Future = Box<futures::Future<Item = Response, Error = Self::Error>>;
|
type Future = Box<dyn futures::Future<Item = Response, Error = Self::Error>>;
|
||||||
|
|
||||||
fn call(&self, req: Request) -> Self::Future {
|
fn call(&self, req: Request) -> Self::Future {
|
||||||
let (method, uri, _http_version, headers, body) = req.deconstruct();
|
let (method, uri, _http_version, headers, body) = req.deconstruct();
|
||||||
|
|
28
src/state.rs
28
src/state.rs
|
@ -7,10 +7,10 @@ use futures_cpupool::{self, CpuFuture};
|
||||||
use r2d2::Pool;
|
use r2d2::Pool;
|
||||||
use r2d2_diesel::ConnectionManager;
|
use r2d2_diesel::ConnectionManager;
|
||||||
|
|
||||||
use merge;
|
use crate::merge;
|
||||||
use models;
|
use crate::models;
|
||||||
use schema::*;
|
use crate::schema::*;
|
||||||
use theme::Theme;
|
use crate::theme::Theme;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct State {
|
pub struct State {
|
||||||
|
@ -18,7 +18,7 @@ pub struct State {
|
||||||
cpu_pool: futures_cpupool::CpuPool,
|
cpu_pool: futures_cpupool::CpuPool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Error = Box<std::error::Error + Send + Sync>;
|
pub type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||||
|
|
||||||
pub enum SlugLookup {
|
pub enum SlugLookup {
|
||||||
Miss,
|
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 };
|
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 slug = base_slug.to_owned();
|
||||||
let mut disambiguator = 1;
|
let mut disambiguator = 1;
|
||||||
|
@ -113,7 +113,7 @@ impl<'a> SyncState<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_article_slug(&self, article_id: i32) -> Result<Option<String>, Error> {
|
pub fn get_article_slug(&self, article_id: i32) -> Result<Option<String>, Error> {
|
||||||
use schema::article_revisions;
|
use crate::schema::article_revisions;
|
||||||
|
|
||||||
Ok(article_revisions::table
|
Ok(article_revisions::table
|
||||||
.filter(article_revisions::article_id.eq(article_id))
|
.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<Option<models::ArticleRevision>, Error> {
|
pub fn get_article_revision(&self, article_id: i32, revision: i32) -> Result<Option<models::ArticleRevision>, Error> {
|
||||||
use schema::article_revisions;
|
use crate::schema::article_revisions;
|
||||||
|
|
||||||
Ok(article_revisions::table
|
Ok(article_revisions::table
|
||||||
.filter(article_revisions::article_id.eq(article_id))
|
.filter(article_revisions::article_id.eq(article_id))
|
||||||
|
@ -140,7 +140,7 @@ impl<'a> SyncState<'a> {
|
||||||
FnOnce(article_revisions::BoxedQuery<'x, diesel::sqlite::Sqlite>) ->
|
FnOnce(article_revisions::BoxedQuery<'x, diesel::sqlite::Sqlite>) ->
|
||||||
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())
|
Ok(f(article_revisions.into_boxed())
|
||||||
.select((
|
.select((
|
||||||
|
@ -159,7 +159,7 @@ impl<'a> SyncState<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_article_revision_stub(&self, article_id: i32, revision: i32) -> Result<Option<models::ArticleRevisionStub>, Error> {
|
fn get_article_revision_stub(&self, article_id: i32, revision: i32) -> Result<Option<models::ArticleRevisionStub>, Error> {
|
||||||
use schema::article_revisions;
|
use crate::schema::article_revisions;
|
||||||
|
|
||||||
Ok(self.query_article_revision_stubs(move |query| {
|
Ok(self.query_article_revision_stubs(move |query| {
|
||||||
query
|
query
|
||||||
|
@ -178,7 +178,7 @@ impl<'a> SyncState<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.db_connection.transaction(|| {
|
self.db_connection.transaction(|| {
|
||||||
use schema::article_revisions;
|
use crate::schema::article_revisions;
|
||||||
|
|
||||||
Ok(match article_revisions::table
|
Ok(match article_revisions::table
|
||||||
.filter(article_revisions::slug.eq(slug))
|
.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_b, body_b, theme_b) = stored.pop().expect("Application layer guarantee");
|
||||||
let (title_o, body_o, theme_o) = 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 {
|
fn merge_themes(a: Theme, o: Theme, b: Theme) -> Theme {
|
||||||
// Last change wins
|
// Last change wins
|
||||||
|
@ -279,7 +279,7 @@ impl<'a> SyncState<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.db_connection.transaction(|| {
|
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
|
let (latest_revision, prev_title, prev_slug, prev_theme) = article_revisions::table
|
||||||
.filter(article_revisions::article_id.eq(article_id))
|
.filter(article_revisions::article_id.eq(article_id))
|
||||||
|
@ -499,7 +499,7 @@ impl State {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use db;
|
use crate::db;
|
||||||
|
|
||||||
impl UpdateResult {
|
impl UpdateResult {
|
||||||
pub fn unwrap(self) -> models::ArticleRevision {
|
pub fn unwrap(self) -> models::ArticleRevision {
|
||||||
|
|
|
@ -188,7 +188,7 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic_db_roundtrip() -> Result<(), Box<Error>> {
|
fn basic_db_roundtrip() -> Result<(), Box<dyn Error>> {
|
||||||
let conn = SqliteConnection::establish(":memory:")?;
|
let conn = SqliteConnection::establish(":memory:")?;
|
||||||
|
|
||||||
#[derive(QueryableByName, PartialEq, Eq, Debug)]
|
#[derive(QueryableByName, PartialEq, Eq, Debug)]
|
||||||
|
@ -204,7 +204,7 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn db_invalid_value_gives_error() -> Result<(), Box<Error>> {
|
fn db_invalid_value_gives_error() -> Result<(), Box<dyn Error>> {
|
||||||
let conn = SqliteConnection::establish(":memory:")?;
|
let conn = SqliteConnection::establish(":memory:")?;
|
||||||
|
|
||||||
#[derive(QueryableByName, PartialEq, Eq, Debug)]
|
#[derive(QueryableByName, PartialEq, Eq, Debug)]
|
||||||
|
|
|
@ -8,8 +8,8 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Error = Box<std::error::Error + Send + Sync>;
|
pub type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||||
pub type ResponseFuture = Box<futures::Future<Item = server::Response, Error = Error>>;
|
pub type ResponseFuture = Box<dyn futures::Future<Item = server::Response, Error = Error>>;
|
||||||
|
|
||||||
pub trait Resource {
|
pub trait Resource {
|
||||||
fn allow(&self) -> Vec<hyper::Method>;
|
fn allow(&self) -> Vec<hyper::Method>;
|
||||||
|
|
|
@ -7,15 +7,15 @@ use futures::future::FutureResult;
|
||||||
use percent_encoding::percent_decode;
|
use percent_encoding::percent_decode;
|
||||||
use slug::slugify;
|
use slug::slugify;
|
||||||
|
|
||||||
use resources::*;
|
use crate::resources::*;
|
||||||
use state::State;
|
use crate::state::State;
|
||||||
use web::{Lookup, Resource};
|
use crate::web::{Lookup, Resource};
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
use assets::*;
|
use crate::assets::*;
|
||||||
|
|
||||||
type BoxResource = Box<Resource + Sync + Send>;
|
type BoxResource = Box<dyn Resource + Sync + Send>;
|
||||||
type ResourceFn = Box<Fn() -> BoxResource + Sync + Send>;
|
type ResourceFn = Box<dyn Fn() -> BoxResource + Sync + Send>;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref LICENSES_MAP: HashMap<&'static str, ResourceFn> = hashmap!{
|
static ref LICENSES_MAP: HashMap<&'static str, ResourceFn> = hashmap!{
|
||||||
|
@ -55,7 +55,7 @@ fn split_one(path: &str) -> Result<(Cow<str>, Option<&str>), Utf8Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_lookup(map: &HashMap<&str, ResourceFn>, path: &str) ->
|
fn map_lookup(map: &HashMap<&str, ResourceFn>, path: &str) ->
|
||||||
FutureResult<Option<BoxResource>, Box<::std::error::Error + Send + Sync>>
|
FutureResult<Option<BoxResource>, Box<dyn ::std::error::Error + Send + Sync>>
|
||||||
{
|
{
|
||||||
let (head, tail) = match split_one(path) {
|
let (head, tail) = match split_one(path) {
|
||||||
Ok(x) => x,
|
Ok(x) => x,
|
||||||
|
@ -74,7 +74,7 @@ fn map_lookup(map: &HashMap<&str, ResourceFn>, path: &str) ->
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
fn fs_lookup(root: &str, path: &str) ->
|
fn fs_lookup(root: &str, path: &str) ->
|
||||||
FutureResult<Option<BoxResource>, Box<::std::error::Error + Send + Sync>>
|
FutureResult<Option<BoxResource>, Box<dyn ::std::error::Error + Send + Sync>>
|
||||||
{
|
{
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
|
@ -93,7 +93,7 @@ fn fs_lookup(root: &str, path: &str) ->
|
||||||
filename.push_str(path);
|
filename.push_str(path);
|
||||||
|
|
||||||
let mut f = File::open(&filename)
|
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();
|
let mut body = Vec::new();
|
||||||
f.read_to_end(&mut body)
|
f.read_to_end(&mut body)
|
||||||
|
@ -233,7 +233,7 @@ impl WikiLookup {
|
||||||
let state = self.state.clone();
|
let state = self.state.clone();
|
||||||
let slug = slug.into_owned();
|
let slug = slug.into_owned();
|
||||||
|
|
||||||
use state::SlugLookup;
|
use crate::state::SlugLookup;
|
||||||
Box::new(self.state.lookup_slug(slug.clone())
|
Box::new(self.state.lookup_slug(slug.clone())
|
||||||
.and_then(move |x| Ok(Some(match x {
|
.and_then(move |x| Ok(Some(match x {
|
||||||
SlugLookup::Miss =>
|
SlugLookup::Miss =>
|
||||||
|
@ -249,8 +249,8 @@ impl WikiLookup {
|
||||||
|
|
||||||
impl Lookup for WikiLookup {
|
impl Lookup for WikiLookup {
|
||||||
type Resource = BoxResource;
|
type Resource = BoxResource;
|
||||||
type Error = Box<::std::error::Error + Send + Sync>;
|
type Error = Box<dyn ::std::error::Error + Send + Sync>;
|
||||||
type Future = Box<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("/"));
|
||||||
|
|
Loading…
Reference in a new issue