Addressed many cargo clippy complaints
This commit is contained in:
parent
95a73b9471
commit
bf34e2923b
13 changed files with 66 additions and 135 deletions
82
Cargo.lock
generated
82
Cargo.lock
generated
|
@ -262,7 +262,7 @@ version = "1.4.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "45f5098f628d02a7a0f68ddba586fb61e80edec3bdc1be3b921f4ceec60858d3"
|
checksum = "45f5098f628d02a7a0f68ddba586fb61e80edec3bdc1be3b921f4ceec60858d3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 1.0.26",
|
"proc-macro2",
|
||||||
"quote 1.0.9",
|
"quote 1.0.9",
|
||||||
"syn 1.0.71",
|
"syn 1.0.71",
|
||||||
]
|
]
|
||||||
|
@ -428,24 +428,10 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indoc"
|
name = "indoc"
|
||||||
version = "0.2.8"
|
version = "1.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "098a82c5223d3162a32d79f84e43d718c32f050d07b796285684ee43059bc8c4"
|
checksum = "e7906a9fababaeacb774f72410e497a1d18de916322e33797bb2cd29baa23c9e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indoc-impl",
|
|
||||||
"proc-macro-hack",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "indoc-impl"
|
|
||||||
version = "0.2.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "55cf2a15c870db1b07595cc9adaece19fac97d59a16665e79cd728b391a6b711"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro-hack",
|
|
||||||
"proc-macro2 0.4.30",
|
|
||||||
"quote 0.6.13",
|
|
||||||
"syn 0.15.44",
|
|
||||||
"unindent",
|
"unindent",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -632,7 +618,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9753f12909fd8d923f75ae5c3258cae1ed3c8ec052e1b38c93c21a6d157f789c"
|
checksum = "9753f12909fd8d923f75ae5c3258cae1ed3c8ec052e1b38c93c21a6d157f789c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"migrations_internals",
|
"migrations_internals",
|
||||||
"proc-macro2 1.0.26",
|
"proc-macro2",
|
||||||
"quote 1.0.9",
|
"quote 1.0.9",
|
||||||
"syn 1.0.71",
|
"syn 1.0.71",
|
||||||
]
|
]
|
||||||
|
@ -822,30 +808,6 @@ version = "0.3.19"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c"
|
checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-hack"
|
|
||||||
version = "0.4.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d7f95648580798cc44ff8efb9bb0d7ee5205ea32e087b31b0732f3e8c2648ee2"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro-hack-impl",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-hack-impl"
|
|
||||||
version = "0.4.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7be55bf0ae1635f4d7c7ddd6efc05c631e98a82104a73d35550bbc52db960027"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro2"
|
|
||||||
version = "0.4.30"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-xid 0.1.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.26"
|
version = "1.0.26"
|
||||||
|
@ -869,22 +831,13 @@ version = "0.3.15"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
|
checksum = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quote"
|
|
||||||
version = "0.6.13"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2 0.4.30",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.9"
|
version = "1.0.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
|
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 1.0.26",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1148,7 +1101,7 @@ version = "1.0.125"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d"
|
checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 1.0.26",
|
"proc-macro2",
|
||||||
"quote 1.0.9",
|
"quote 1.0.9",
|
||||||
"syn 1.0.71",
|
"syn 1.0.71",
|
||||||
]
|
]
|
||||||
|
@ -1267,24 +1220,13 @@ dependencies = [
|
||||||
"unicode-xid 0.0.4",
|
"unicode-xid 0.0.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "0.15.44"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2 0.4.30",
|
|
||||||
"quote 0.6.13",
|
|
||||||
"unicode-xid 0.1.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.71"
|
version = "1.0.71"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ad184cc9470f9117b2ac6817bfe297307418819ba40552f9b3846f05c33d5373"
|
checksum = "ad184cc9470f9117b2ac6817bfe297307418819ba40552f9b3846f05c33d5373"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 1.0.26",
|
"proc-macro2",
|
||||||
"quote 1.0.9",
|
"quote 1.0.9",
|
||||||
"unicode-xid 0.2.2",
|
"unicode-xid 0.2.2",
|
||||||
]
|
]
|
||||||
|
@ -1643,12 +1585,6 @@ version = "0.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
|
checksum = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-xid"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-xid"
|
name = "unicode-xid"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
|
@ -1657,9 +1593,9 @@ checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unindent"
|
name = "unindent"
|
||||||
version = "0.1.7"
|
version = "0.1.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f14ee04d9415b52b3aeab06258a3f07093182b88ba0f9b8d203f211a7a7d41c7"
|
checksum = "514672a55d7380da379785a4d70ca8386c8883ff7eaae877be4d2081cebe73d8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "url"
|
name = "url"
|
||||||
|
|
|
@ -79,7 +79,7 @@ default-features = false
|
||||||
git = "https://github.com/maghoff/pulldown-cmark.git"
|
git = "https://github.com/maghoff/pulldown-cmark.git"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
indoc = "0.2"
|
indoc = "1.0.4"
|
||||||
matches = "0.1"
|
matches = "0.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|
|
@ -19,7 +19,7 @@ impl LicenseId {
|
||||||
fn include_notice(&self) -> bool {
|
fn include_notice(&self) -> bool {
|
||||||
use self::LicenseId::*;
|
use self::LicenseId::*;
|
||||||
match self {
|
match self {
|
||||||
&Mpl2 => false,
|
Mpl2 => false,
|
||||||
_ => true,
|
_ => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,10 +29,10 @@ impl quote::ToTokens for LicenseId {
|
||||||
fn to_tokens(&self, tokens: &mut quote::Tokens) {
|
fn to_tokens(&self, tokens: &mut quote::Tokens) {
|
||||||
use self::LicenseId::*;
|
use self::LicenseId::*;
|
||||||
tokens.append(match self {
|
tokens.append(match self {
|
||||||
&Bsd3Clause => "Bsd3Clause",
|
Bsd3Clause => "Bsd3Clause",
|
||||||
&Mit => "Mit",
|
Mit => "Mit",
|
||||||
&Mpl2 => "Mpl2",
|
Mpl2 => "Mpl2",
|
||||||
&Ofl11 => "Ofl11",
|
Ofl11 => "Ofl11",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,9 +60,9 @@ impl quote::ToTokens for LicenseReport {
|
||||||
&c.chosen_license,
|
&c.chosen_license,
|
||||||
);
|
);
|
||||||
|
|
||||||
let link = match link {
|
let link = match *link {
|
||||||
&Some(ref link) => quote! { Some(#link) },
|
Some(ref link) => quote! { Some(#link) },
|
||||||
&None => quote! { None },
|
None => quote! { None },
|
||||||
};
|
};
|
||||||
|
|
||||||
let copyright = match license.include_notice() {
|
let copyright = match license.include_notice() {
|
||||||
|
|
|
@ -10,12 +10,12 @@ fn user_crate_root() -> PathBuf {
|
||||||
std::env::current_dir().expect("Unable to get current directory")
|
std::env::current_dir().expect("Unable to get current directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_attr<'a>(attrs: &'a Vec<syn::Attribute>, name: &str) -> Option<&'a str> {
|
fn find_attr<'a>(attrs: &'a [syn::Attribute], name: &str) -> Option<&'a str> {
|
||||||
attrs
|
attrs
|
||||||
.iter()
|
.iter()
|
||||||
.find(|&x| x.name() == name)
|
.find(|&x| x.name() == name)
|
||||||
.and_then(|ref attr| match &attr.value {
|
.and_then(|attr| match attr.value {
|
||||||
&syn::MetaItem::NameValue(_, syn::Lit::Str(ref template, _)) => Some(template),
|
syn::MetaItem::NameValue(_, syn::Lit::Str(ref template, _)) => Some(template),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.map(|x| x.as_ref())
|
.map(|x| x.as_ref())
|
||||||
|
|
|
@ -12,7 +12,7 @@ compile_error!("dynamic-assets must not be used for production");
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref VERSION: String = || -> String {
|
pub static ref VERSION: String = || -> String {
|
||||||
let mut components = Vec::<String>::new();
|
let mut components = vec![];
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
components.push("debug".into());
|
components.push("debug".into());
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#![allow(clippy::into_iter_on_ref)]
|
||||||
|
#![allow(clippy::vec_init_then_push)]
|
||||||
#![recursion_limit = "128"]
|
#![recursion_limit = "128"]
|
||||||
// for diesel's infer_schema!
|
// for diesel's infer_schema!
|
||||||
|
|
||||||
|
@ -9,15 +11,12 @@
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate matches;
|
extern crate matches;
|
||||||
#[cfg(test)]
|
|
||||||
#[macro_use]
|
|
||||||
extern crate indoc;
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate bart_derive;
|
extern crate bart_derive;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate codegen;
|
extern crate codegen;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
#[allow(clippy::useless_attribute)]
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
extern crate diesel_infer_schema;
|
extern crate diesel_infer_schema;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
|
@ -17,11 +17,11 @@ pub enum MergeResult<Item: Debug + PartialEq> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> MergeResult<&'a str> {
|
impl<'a> MergeResult<&'a str> {
|
||||||
pub fn to_strings(self) -> MergeResult<String> {
|
pub fn into_strings(self) -> MergeResult<String> {
|
||||||
match self {
|
match self {
|
||||||
MergeResult::Clean(x) => MergeResult::Clean(x),
|
MergeResult::Clean(x) => MergeResult::Clean(x),
|
||||||
MergeResult::Conflicted(x) => {
|
MergeResult::Conflicted(x) => {
|
||||||
MergeResult::Conflicted(x.into_iter().map(Output::to_strings).collect())
|
MergeResult::Conflicted(x.into_iter().map(Output::into_strings).collect())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,10 +80,7 @@ pub fn merge_lines<'a>(a: &'a str, o: &'a str, b: &'a str) -> MergeResult<&'a st
|
||||||
let chunks = ChunkIterator::new(&oa, &ob);
|
let chunks = ChunkIterator::new(&oa, &ob);
|
||||||
let hunks: Vec<_> = chunks.map(resolve).collect();
|
let hunks: Vec<_> = chunks.map(resolve).collect();
|
||||||
|
|
||||||
let clean = hunks.iter().all(|x| match x {
|
let clean = hunks.iter().all(|x| matches!(x, Resolved(..)));
|
||||||
&Resolved(..) => true,
|
|
||||||
_ => false,
|
|
||||||
});
|
|
||||||
|
|
||||||
if clean {
|
if clean {
|
||||||
MergeResult::Clean(
|
MergeResult::Clean(
|
||||||
|
@ -108,10 +105,7 @@ pub fn merge_chars<'a>(a: &'a str, o: &'a str, b: &'a str) -> MergeResult<char>
|
||||||
let chunks = ChunkIterator::new(&oa, &ob);
|
let chunks = ChunkIterator::new(&oa, &ob);
|
||||||
let hunks: Vec<_> = chunks.map(resolve).collect();
|
let hunks: Vec<_> = chunks.map(resolve).collect();
|
||||||
|
|
||||||
let clean = hunks.iter().all(|x| match x {
|
let clean = hunks.iter().all(|x| matches!(x, Resolved(..)));
|
||||||
&Resolved(..) => true,
|
|
||||||
_ => false,
|
|
||||||
});
|
|
||||||
|
|
||||||
if clean {
|
if clean {
|
||||||
MergeResult::Clean(
|
MergeResult::Clean(
|
||||||
|
@ -130,6 +124,7 @@ 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 indoc::indoc;
|
||||||
|
|
||||||
use super::output::Output::*;
|
use super::output::Output::*;
|
||||||
use super::output::*;
|
use super::output::*;
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub enum Output<Item: Debug + PartialEq> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Output<&'a str> {
|
impl<'a> Output<&'a str> {
|
||||||
pub fn to_strings(self) -> Output<String> {
|
pub fn into_strings(self) -> Output<String> {
|
||||||
match self {
|
match self {
|
||||||
Output::Resolved(x) => Output::Resolved(x.into_iter().map(str::to_string).collect()),
|
Output::Resolved(x) => Output::Resolved(x.into_iter().map(str::to_string).collect()),
|
||||||
Output::Conflict(a, o, b) => Output::Conflict(
|
Output::Conflict(a, o, b) => Output::Conflict(
|
||||||
|
@ -26,10 +26,10 @@ impl<'a> Output<&'a str> {
|
||||||
fn choose_left<Item: Copy>(operations: &[diff::Result<Item>]) -> Vec<Item> {
|
fn choose_left<Item: Copy>(operations: &[diff::Result<Item>]) -> Vec<Item> {
|
||||||
operations
|
operations
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|x| match x {
|
.filter_map(|x| match *x {
|
||||||
&Both(y, _) => Some(y),
|
Both(y, _) => Some(y),
|
||||||
&Left(y) => Some(y),
|
Left(y) => Some(y),
|
||||||
&Right(_) => None,
|
Right(_) => None,
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -37,19 +37,16 @@ fn choose_left<Item: Copy>(operations: &[diff::Result<Item>]) -> Vec<Item> {
|
||||||
fn choose_right<Item: Copy>(operations: &[diff::Result<Item>]) -> Vec<Item> {
|
fn choose_right<Item: Copy>(operations: &[diff::Result<Item>]) -> Vec<Item> {
|
||||||
operations
|
operations
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|x| match x {
|
.filter_map(|x| match *x {
|
||||||
&Both(_, y) => Some(y),
|
Both(_, y) => Some(y),
|
||||||
&Left(_) => None,
|
Left(_) => None,
|
||||||
&Right(y) => Some(y),
|
Right(y) => Some(y),
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn no_change<Item>(operations: &[diff::Result<Item>]) -> bool {
|
fn no_change<Item>(operations: &[diff::Result<Item>]) -> bool {
|
||||||
operations.iter().all(|x| match x {
|
operations.iter().all(|x| matches!(x, Both(..)))
|
||||||
&Both(..) => true,
|
|
||||||
_ => false,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve<'a, Item: 'a + Debug + PartialEq + Copy>(chunk: Chunk<'a, Item>) -> Output<Item> {
|
pub fn resolve<'a, Item: 'a + Debug + PartialEq + Copy>(chunk: Chunk<'a, Item>) -> Output<Item> {
|
||||||
|
|
|
@ -28,20 +28,20 @@ impl License {
|
||||||
fn link(&self) -> &'static str {
|
fn link(&self) -> &'static str {
|
||||||
use self::License::*;
|
use self::License::*;
|
||||||
match self {
|
match self {
|
||||||
&Bsd3Clause => "bsd-3-clause",
|
Bsd3Clause => "bsd-3-clause",
|
||||||
&Mit => "mit",
|
Mit => "mit",
|
||||||
&Mpl2 => "mpl2",
|
Mpl2 => "mpl2",
|
||||||
&Ofl11 => "sil-ofl-1.1",
|
Ofl11 => "sil-ofl-1.1",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn name(&self) -> &'static str {
|
fn name(&self) -> &'static str {
|
||||||
use self::License::*;
|
use self::License::*;
|
||||||
match self {
|
match self {
|
||||||
&Bsd3Clause => "BSD-3-Clause",
|
Bsd3Clause => "BSD-3-Clause",
|
||||||
&Mit => "MIT",
|
Mit => "MIT",
|
||||||
&Mpl2 => "MPL2",
|
Mpl2 => "MPL2",
|
||||||
&Ofl11 => "OFL-1.1",
|
Ofl11 => "OFL-1.1",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,12 +81,12 @@ impl QueryParameters {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_query_config<'a>(
|
fn apply_query_config(
|
||||||
mut query: article_revisions::BoxedQuery<'a, diesel::sqlite::Sqlite>,
|
mut query: article_revisions::BoxedQuery<diesel::sqlite::Sqlite>,
|
||||||
article_id: Option<i32>,
|
article_id: Option<i32>,
|
||||||
author: Option<String>,
|
author: Option<String>,
|
||||||
limit: i32,
|
limit: i32,
|
||||||
) -> article_revisions::BoxedQuery<'a, diesel::sqlite::Sqlite> {
|
) -> article_revisions::BoxedQuery<diesel::sqlite::Sqlite> {
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
|
|
||||||
if let Some(article_id) = article_id {
|
if let Some(article_id) = article_id {
|
||||||
|
|
|
@ -152,9 +152,9 @@ impl Resource for SearchResource {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn head(&self) -> ResponseFuture {
|
fn head(&self) -> ResponseFuture {
|
||||||
let content_type = match &self.response_type {
|
let content_type = match self.response_type {
|
||||||
&ResponseType::Json => ContentType(APPLICATION_JSON.clone()),
|
ResponseType::Json => ContentType(APPLICATION_JSON.clone()),
|
||||||
&ResponseType::Html => ContentType(TEXT_HTML.clone()),
|
ResponseType::Html => ContentType(TEXT_HTML.clone()),
|
||||||
};
|
};
|
||||||
|
|
||||||
Box::new(futures::finished(
|
Box::new(futures::finished(
|
||||||
|
@ -183,7 +183,11 @@ 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.query.as_ref().cloned().unwrap_or("".to_owned());
|
let query = self
|
||||||
|
.query
|
||||||
|
.as_ref()
|
||||||
|
.cloned()
|
||||||
|
.unwrap_or_else(|| "".to_owned());
|
||||||
|
|
||||||
let data = self.state.search_query(
|
let data = self.state.search_query(
|
||||||
query,
|
query,
|
||||||
|
@ -215,8 +219,8 @@ impl Resource for SearchResource {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
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_deref().unwrap_or(""),
|
query: self.query.as_deref().unwrap_or(""),
|
||||||
hits: &data,
|
hits: &data,
|
||||||
|
@ -225,7 +229,7 @@ impl Resource for SearchResource {
|
||||||
})
|
})
|
||||||
.expect("Should never fail"),
|
.expect("Should never fail"),
|
||||||
)),
|
)),
|
||||||
&ResponseType::Html => Ok(head.with_body(
|
ResponseType::Html => Ok(head.with_body(
|
||||||
system_page(
|
system_page(
|
||||||
None, // Hmm, should perhaps accept `base` as argument
|
None, // Hmm, should perhaps accept `base` as argument
|
||||||
"Search",
|
"Search",
|
||||||
|
|
|
@ -143,7 +143,7 @@ impl Service for Site {
|
||||||
false => None,
|
false => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let accept_header = headers.get().cloned().unwrap_or(Accept(vec![]));
|
let accept_header = headers.get().cloned().unwrap_or_else(|| 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
|
||||||
|
|
|
@ -281,7 +281,7 @@ impl<'a> SyncState<'a> {
|
||||||
.get_article_revision_stub(article_id, revision + 1)?
|
.get_article_revision_stub(article_id, revision + 1)?
|
||||||
.expect("Application layer guarantee"),
|
.expect("Application layer guarantee"),
|
||||||
title: title_merge,
|
title: title_merge,
|
||||||
body: body_merge.to_strings(),
|
body: body_merge.into_strings(),
|
||||||
theme,
|
theme,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -625,7 +625,7 @@ mod test {
|
||||||
.create_article(None, "Title".into(), "Body".into(), None, Theme::Cyan)
|
.create_article(None, "Title".into(), "Body".into(), None, Theme::Cyan)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!("title", article_revision.slug);
|
assert_eq!("title", article_revision.slug);
|
||||||
assert_eq!(true, article_revision.latest);
|
assert!(article_revision.latest);
|
||||||
assert_eq!(Theme::Cyan, article_revision.theme);
|
assert_eq!(Theme::Cyan, article_revision.theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -896,7 +896,7 @@ mod test {
|
||||||
vec!["a"],
|
vec!["a"],
|
||||||
vec!["b"]
|
vec!["b"]
|
||||||
),])
|
),])
|
||||||
.to_strings()
|
.into_strings()
|
||||||
);
|
);
|
||||||
assert_eq!(Theme::Amber, theme);
|
assert_eq!(Theme::Amber, theme);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue