summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKornel <kornel@geekhood.net>2019-08-07 22:22:55 +0100
committerKornel <kornel@geekhood.net>2019-08-09 13:04:15 +0100
commit47c02f92e70748c189b1f0730c0ee76a451f6403 (patch)
treef6ba9b1f31986f6eb4956c6321db5da708735166
parent316f149b27c7ed3e51245f7a9eed7c9620c1c93b (diff)
Rustfmt
-rw-r--r--categories/src/categories.rs11
-rw-r--r--crate_db/src/lib_crate_db.rs41
-rw-r--r--crate_db/src/stopwords.rs1
-rw-r--r--front_end/src/bin/crate_pages.rs2
-rw-r--r--front_end/src/crate_page.rs2
-rw-r--r--front_end/src/front_end.rs11
-rw-r--r--front_end/src/home_page.rs19
-rw-r--r--front_end/src/not_found_page.rs8
-rw-r--r--front_end/src/search_page.rs2
-rw-r--r--front_end/src/urler.rs4
-rw-r--r--github_info/src/model.rs57
-rw-r--r--kitchen_sink/src/index.rs4
-rw-r--r--kitchen_sink/src/lib_kitchen_sink.rs14
-rw-r--r--rich_crate/src/lib.rs14
-rw-r--r--rich_crate/src/rich_crate_version.rs3
-rw-r--r--server/src/main.rs60
-rw-r--r--server/src/writer.rs2
-rw-r--r--udedokei/src/lib.rs6
-rw-r--r--user_db/src/lib_user_db.rs2
19 files changed, 120 insertions, 143 deletions
diff --git a/categories/src/categories.rs b/categories/src/categories.rs
index 367e940..6718063 100644
--- a/categories/src/categories.rs
+++ b/categories/src/categories.rs
@@ -84,7 +84,7 @@ impl Categories {
let obvious_keywords = details.remove("obvious-keywords").and_then(|v| v.try_into().ok()).unwrap_or_default();
let siblings = details.remove("siblings").and_then(|v| v.try_into().ok()).unwrap_or_default();
- let mut full_slug = String::with_capacity(full_slug_start.len()+2+slug.len());
+ let mut full_slug = String::with_capacity(full_slug_start.len() + 2 + slug.len());
if full_slug_start != "" {
full_slug.push_str(full_slug_start);
full_slug.push_str("::");
@@ -126,7 +126,8 @@ impl Categories {
}
pub fn fixed_category_slugs(cats: &[String]) -> Vec<Cow<'_, str>> {
- let mut cats = Self::filtered_category_slugs(cats).enumerate().filter_map(|(idx, s)| {
+ let mut cats = Self::filtered_category_slugs(cats).enumerate()
+ .filter_map(|(idx, s)| {
let s = s.trim_matches(':');
let mut chars = s.chars().peekable();
while let Some(cur) = chars.next() {
@@ -151,13 +152,15 @@ impl Categories {
}
let depth = s.split("::").count();
Some((depth, idx, Cow::Borrowed(s.as_ref())))
- }).filter(|(_, _, s)| {
+ })
+ .filter(|(_, _, s)| {
if CATEGORIES.from_slug(s).next().is_none() {
println!("invalid cat name {}", s);
return false;
}
true
- }).collect::<Vec<_>>();
+ })
+ .collect::<Vec<_>>();
// depth, then original order
cats.sort_by(|a, b| b.0.cmp(&a.0).then(a.1.cmp(&b.1)));
diff --git a/crate_db/src/lib_crate_db.rs b/crate_db/src/lib_crate_db.rs
index f4e8235..34f681d 100644
--- a/crate_db/src/lib_crate_db.rs
+++ b/crate_db/src/lib_crate_db.rs
@@ -1,35 +1,25 @@
use categories;
-use rusqlite::types::ToSql;
-use rusqlite::NO_PARAMS;
-use std::fmt::Write;
-
-use rusqlite;
-#[macro_use]
-extern crate failure;
-
-#[macro_use]
-extern crate lazy_static;
-
use chrono::prelude::*;
-use failure::ResultExt;
-
+use failure::*;
+use parking_lot::Mutex;
use rich_crate::Derived;
use rich_crate::Manifest;
+use rich_crate::ManifestExt;
+use rich_crate::Markup;
use rich_crate::Origin;
-use rich_crate::Repo;
use rich_crate::Readme;
-use rich_crate::Markup;
+use rich_crate::Repo;
use rich_crate::RichCrate;
-use rich_crate::ManifestExt;
-
use rusqlite::*;
+use rusqlite::NO_PARAMS;
+use rusqlite::types::ToSql;
use std::borrow::Cow;
use std::cell::RefCell;
use std::collections::HashMap;
use std::collections::HashSet;
+use std::fmt::Write;
use std::fs;
use std::path::Path;
-use parking_lot::Mutex;
use thread_local::ThreadLocal;
type FResult<T> = std::result::Result<T, failure::Error>;
@@ -309,8 +299,7 @@ impl CrateDb {
tmp.sort_by(|a, b| b.1.partial_cmp(a.1).unwrap());
write!(&mut out, "#{} ", tmp.into_iter().map(|(k, _)| k.to_string()).collect::<Vec<_>>().join(" #"))?;
}
- let next_timestamp = (Utc::now().timestamp() + 3600*24*31) as u32;
-
+ let next_timestamp = (Utc::now().timestamp() + 3600 * 24 * 31) as u32;
self.with_tx("insert_crate", |tx| {
let mut insert_crate = tx.prepare_cached("INSERT OR IGNORE INTO crates (origin, recent_downloads, ranking) VALUES (?1, ?2, ?3)")?;
@@ -580,16 +569,14 @@ impl CrateDb {
}
pub fn path_in_repo(&self, repo: &Repo, crate_name: &str) -> FResult<Option<String>> {
- self.with_connection("path_in_repo", |conn| {
- self.path_in_repo_tx(conn, repo, crate_name)
- })
+ self.with_connection("path_in_repo", |conn| self.path_in_repo_tx(conn, repo, crate_name))
}
pub fn path_in_repo_tx(&self, conn: &Connection, repo: &Repo, crate_name: &str) -> FResult<Option<String>> {
let repo = repo.canonical_git_url();
- let mut get_path = conn.prepare_cached("SELECT path FROM repo_crates WHERE repo = ?1 AND crate_name = ?2")?;
- let args: &[&dyn ToSql] = &[&repo, &crate_name];
- Ok(none_rows(get_path.query_row(args, |row| row.get(0))).context("path_in_repo")?)
+ let mut get_path = conn.prepare_cached("SELECT path FROM repo_crates WHERE repo = ?1 AND crate_name = ?2")?;
+ let args: &[&dyn ToSql] = &[&repo, &crate_name];
+ Ok(none_rows(get_path.query_row(args, |row| row.get(0))).context("path_in_repo")?)
}
/// Update download counts of the crate
@@ -1105,7 +1092,6 @@ impl KeywordInsert {
}
}
-
fn chop3words(s: &str) -> &str {
let mut words = 0;
for (pos, ch) in s.char_indices() {
@@ -1119,7 +1105,6 @@ fn chop3words(s: &str) -> &str {
return s;
}
-
#[inline]
fn none_rows<T>(res: std::result::Result<T, rusqlite::Error>) -> std::result::Result<Option<T>, rusqlite::Error> {
match res {
diff --git a/crate_db/src/stopwords.rs b/crate_db/src/stopwords.rs
index fb17823..05a00ca 100644
--- a/crate_db/src/stopwords.rs
+++ b/crate_db/src/stopwords.rs
@@ -1,3 +1,4 @@
+use lazy_static::lazy_static;
use std::collections::{HashMap, HashSet};
lazy_static! {
diff --git a/front_end/src/bin/crate_pages.rs b/front_end/src/bin/crate_pages.rs
index 83c2013..d196f7a 100644
--- a/front_end/src/bin/crate_pages.rs
+++ b/front_end/src/bin/crate_pages.rs
@@ -1,3 +1,4 @@
+use either::Either;
use front_end;
use kitchen_sink;
use kitchen_sink::RichCrate;
@@ -8,7 +9,6 @@ use rich_crate::RichCrateVersion;
use std::fs;
use std::path::PathBuf;
use std::sync::Arc;
-use either::Either;
fn main() {
if let Err(e) = run(std::env::args().nth(1)) {
diff --git a/front_end/src/crate_page.rs b/front_end/src/crate_page.rs
index c229f16..4b0770e 100644
--- a/front_end/src/crate_page.rs
+++ b/front_end/src/crate_page.rs
@@ -27,8 +27,8 @@ use std::collections::HashSet;
use std::f64::consts::PI;
use std::fmt::Display;
use std::hash::Hash;
-use udedokei::{Language, Lines, Stats};
use udedokei::LanguageExt;
+use udedokei::{Language, Lines, Stats};
use url::Url;
/// Data sources used in `crate_page.rs.html`
diff --git a/front_end/src/front_end.rs b/front_end/src/front_end.rs
index 86a1a03..718f801 100644
--- a/front_end/src/front_end.rs
+++ b/front_end/src/front_end.rs
@@ -5,24 +5,23 @@
//! because the template engine Ructe doesn't support
//! complex expressions in the templates.
-
mod cat_page;
mod crate_page;
mod download_graph;
mod home_page;
-mod not_found_page;
mod iter;
+mod not_found_page;
mod search_page;
mod urler;
-pub use crate::search_page::*;
pub use crate::not_found_page::*;
+pub use crate::search_page::*;
-use categories::Category;
-use chrono::prelude::*;
use crate::crate_page::*;
use crate::urler::Urler;
-use failure::ResultExt;
+use categories::Category;
+use chrono::prelude::*;
use failure;
+use failure::ResultExt;
use kitchen_sink::KitchenSink;
use kitchen_sink::{stopped, KitchenSinkErr};
use render_readme::Renderer;
diff --git a/front_end/src/home_page.rs b/front_end/src/home_page.rs
index 7b38b0c..c4c0d9e 100644
--- a/front_end/src/home_page.rs
+++ b/front_end/src/home_page.rs
@@ -163,16 +163,21 @@ impl<'a> HomePage<'a> {
}
pub fn all_contributors<'c>(&self, krate: &'c RichCrateVersion) -> Option<Vec<CrateAuthor<'c>>> {
- self.crates.all_contributors(krate).map(|(mut a,mut o,..)| {
- a.append(&mut o);
- a
- }).ok()
+ self.crates
+ .all_contributors(krate)
+ .map(|(mut a, mut o, ..)| {
+ a.append(&mut o);
+ a
+ })
+ .ok()
}
pub fn recently_updated_crates<'z>(&'z self) -> impl Iterator<Item = (RichCrate, RichCrateVersion)> + 'z {
- self.crates.recently_updated_crates().expect("recent crates").into_iter().map(move |o| {
- (self.crates.rich_crate(&o).unwrap(), self.crates.rich_crate_version(&o).unwrap())
- })
+ self.crates
+ .recently_updated_crates()
+ .expect("recent crates")
+ .into_iter()
+ .map(move |o| (self.crates.rich_crate(&o).unwrap(), self.crates.rich_crate_version(&o).unwrap()))
}
pub fn page(&self) -> Page {
diff --git a/front_end/src/not_found_page.rs b/front_end/src/not_found_page.rs
index bcfec64..65b471b 100644
--- a/front_end/src/not_found_page.rs
+++ b/front_end/src/not_found_page.rs
@@ -4,7 +4,6 @@ use crate::Urler;
use render_readme::Renderer;
use std::io::Write;
-
pub struct NotFoundPage<'a> {
markup: &'a Renderer,
pub results: &'a [search_index::CrateFound],
@@ -13,15 +12,10 @@ pub struct NotFoundPage<'a> {
impl NotFoundPage<'_> {
pub fn new<'a>(query: &'a str, results: &'a [search_index::CrateFound], markup: &'a Renderer) -> NotFoundPage<'a> {
- NotFoundPage {
- query,
- markup,
- results,
- }
+ NotFoundPage { query, markup, results }
}
pub fn page(&self) -> Page {
-
Page {
title: "Crate not found".into(),
description: Some("Error".into()),
diff --git a/front_end/src/search_page.rs b/front_end/src/search_page.rs
index 7a8046d..fea00ad 100644
--- a/front_end/src/search_page.rs
+++ b/front_end/src/search_page.rs
@@ -2,8 +2,8 @@ use crate::templates;
use crate::Page;
use crate::Urler;
use render_readme::Renderer;
-use std::io::Write;
use std::collections::HashMap;
+use std::io::Write;
pub enum SearchKind<'a> {
Query(&'a str),
diff --git a/front_end/src/urler.rs b/front_end/src/urler.rs
index 921a00f..cda9be2 100644
--- a/front_end/src/urler.rs
+++ b/front_end/src/urler.rs
@@ -14,9 +14,7 @@ pub struct Urler {
impl Urler {
pub fn new(own_crate_name: Option<String>) -> Self {
- Self {
- own_crate_name,
- }
+ Self { own_crate_name }
}
/// Link to a dependency of a crate
diff --git a/github_info/src/model.rs b/github_info/src/model.rs
index eb11242..cf78608 100644
--- a/github_info/src/model.rs
+++ b/github_info/src/model.rs
@@ -1,4 +1,3 @@
-
#[derive(Debug, Copy, Eq, PartialEq, Clone)]
pub enum UserType {
Org,
@@ -6,11 +5,11 @@ pub enum UserType {
Bot,
}
-use serde::Serializer;
use serde::de;
use serde::de::{Deserializer, Visitor};
-use serde::Serialize;
use serde::Deserialize;
+use serde::Serialize;
+use serde::Serializer;
use std::fmt;
/// Case-insensitive enum
@@ -62,23 +61,23 @@ pub struct User {
pub id: u32,
pub login: String,
pub name: Option<String>,
- pub avatar_url: Option<String>, // "https://avatars0.githubusercontent.com/u/1111?v=4",
+ pub avatar_url: Option<String>, // "https://avatars0.githubusercontent.com/u/1111?v=4",
pub gravatar_id: Option<String>, // "",
- pub html_url: String, // "https://github.com/zzzz",
- pub blog: Option<String>, // "https://example.com
- #[serde(rename="type")]
+ pub html_url: String, // "https://github.com/zzzz",
+ pub blog: Option<String>, // "https://example.com
+ #[serde(rename = "type")]
pub user_type: UserType,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContribWeek {
- #[serde(rename="w")]
+ #[serde(rename = "w")]
pub week_timestamp: u32,
- #[serde(rename="a")]
+ #[serde(rename = "a")]
pub added: u32,
- #[serde(rename="d")]
+ #[serde(rename = "d")]
pub deleted: u32,
- #[serde(rename="c")]
+ #[serde(rename = "c")]
pub commits: u32,
}
@@ -128,8 +127,8 @@ pub struct GitHubRepo {
pub updated_at: Option<String>,
pub pushed_at: Option<String>,
pub homepage: Option<String>,
- pub stargazers_count: u32, // Stars
- pub forks_count: u32, // Real number of forks
+ pub stargazers_count: u32, // Stars
+ pub forks_count: u32, // Real number of forks
pub subscribers_count: u32, // Real number of watches
pub has_issues: bool,
pub open_issues_count: Option<u32>,
@@ -152,22 +151,22 @@ pub struct GitHubRepo {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GitHubRelease {
- // url: Option<String>, // "https://api.github.com/repos/octocat/Hello-World/releases/1",
- // html_url: Option<String>, // "https://github.com/octocat/Hello-World/releases/v1.0.0",
- // assets_url: Option<String>, // "https://api.github.com/repos/octocat/Hello-World/releases/1/assets",
- // upload_url: Option<String>, // "https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}",
- // tarball_url: Option<String>, // "https://api.github.com/repos/octocat/Hello-World/tarball/v1.0.0",
- // zipball_url: Option<String>, // "https://api.github.com/repos/octocat/Hello-World/zipball/v1.0.0",
- // id: Option<String>, // 1,
- // node_id: Option<String>, // "MDc6UmVsZWFzZTE=",
- pub tag_name: Option<String>, // "v1.0.0",
- // target_commitish: Option<String>, // "master",
- // name: Option<String>, // "v1.0.0",
- pub body: Option<String>, // "Description of the release",
- pub draft: Option<bool>, // false,
- pub prerelease: Option<bool>, // false,
- pub created_at: Option<String>, // "2013-02-27T19:35:32Z",
- pub published_at: Option<String>, // "2013-02-27T19:35:32Z",
+ // url: Option<String>, // "https://api.github.com/repos/octocat/Hello-World/releases/1",
+ // html_url: Option<String>, // "https://github.com/octocat/Hello-World/releases/v1.0.0",
+ // assets_url: Option<String>, // "https://api.github.com/repos/octocat/Hello-World/releases/1/assets",
+ // upload_url: Option<String>, // "https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}",
+ // tarball_url: Option<String>, // "https://api.github.com/repos/octocat/Hello-World/tarball/v1.0.0",
+ // zipball_url: Option<String>, // "https://api.github.com/repos/octocat/Hello-World/zipball/v1.0.0",
+ // id: Option<String>, // 1,
+ // node_id: Option<String>, // "MDc6UmVsZWFzZTE=",
+ pub tag_name: Option<String>, // "v1.0.0",
+ // target_commitish: Option<String>, // "master",
+ // name: Option<String>, // "v1.0.0",
+ pub body: Option<String>, // "Description of the release",
+ pub draft: Option<bool>, // false,
+ pub prerelease: Option<bool>, // false,
+ pub created_at: Option<String>, // "2013-02-27T19:35:32Z",
+ pub published_at: Option<String>, // "2013-02-27T19:35:32Z",
}
#[derive(Debug, Clone, Serialize, Deserialize)]
diff --git a/kitchen_sink/src/index.rs b/kitchen_sink/src/index.rs
index 7cb7e19..d54ddbe 100644
--- a/kitchen_sink/src/index.rs
+++ b/kitchen_sink/src/index.rs
@@ -2,13 +2,13 @@ use crate::deps_stats::DepsStats;
use crate::git_crates_index::*;
use crate::KitchenSink;
use crate::KitchenSinkErr;
+use crates_index;
use crates_index::Crate;
use crates_index::Version;
-use crates_index;
use fxhash::{FxHashMap, FxHashSet};
use lazyonce::LazyOnce;
-use parking_lot::RwLock;
use parking_lot::Mutex;
+use parking_lot::RwLock;
use rich_crate::Origin;
use semver::Version as SemVer;
use semver::VersionReq;
diff --git a/kitchen_sink/src/lib_kitchen_sink.rs b/kitchen_sink/src/lib_kitchen_sink.rs
index 5a2750a..7eb7a7f 100644
--- a/kitchen_sink/src/lib_kitchen_sink.rs
+++ b/kitchen_sink/src/lib_kitchen_sink.rs
@@ -16,18 +16,18 @@ mod ctrlcbreak;
pub use crate::ctrlcbreak::*;
pub use crates_index::Crate as CratesIndexCrate;
-pub use crates_io_client::CrateDependency;
pub use crates_io_client::CrateDepKind;
+pub use crates_io_client::CrateDependency;
pub use crates_io_client::CrateMetaVersion;
pub use crates_io_client::CratesIoCrate;
pub use crates_io_client::OwnerKind;
pub use github_info::User;
pub use github_info::UserOrg;
pub use github_info::UserType;
-use rich_crate::ManifestExt;
pub use rich_crate::Edition;
pub use rich_crate::Include;
pub use rich_crate::MaintenanceStatus;
+use rich_crate::ManifestExt;
pub use rich_crate::Markup;
pub use rich_crate::Origin;
pub use rich_crate::RichCrate;
@@ -39,9 +39,9 @@ pub use semver::Version as SemVer;
use cargo_toml::Manifest;
use cargo_toml::Package;
use categories::Category;
-use chrono::DateTime;
use chrono::prelude::*;
-use crate_db::{CrateDb, RepoChange, CrateVersionData};
+use chrono::DateTime;
+use crate_db::{CrateDb, CrateVersionData, RepoChange};
use crate_files::CrateFile;
use crates_index::Version;
use crates_io_client::CrateOwner;
@@ -51,6 +51,7 @@ use github_info::GitCommitAuthor;
use github_info::GitHubRepo;
use itertools::Itertools;
use lazyonce::LazyOnce;
+use parking_lot::RwLock;
use rayon::prelude::*;
use repo_url::Repo;
use repo_url::RepoHost;
@@ -72,7 +73,6 @@ use std::env;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::SystemTime;
-use parking_lot::RwLock;
pub type CError = failure::Error;
pub type CResult<T> = Result<T, CError>;
@@ -315,9 +315,7 @@ impl KitchenSink {
pub fn crate_exists(&self, origin: &Origin) -> bool {
match origin {
- Origin::CratesIo(name) => {
- self.index.crates_io_crate_by_name(name).is_ok()
- },
+ Origin::CratesIo(name) => self.index.crates_io_crate_by_name(name).is_ok(),
_ => self.rich_crate(origin).is_ok(),
}
}
diff --git a/rich_crate/src/lib.rs b/rich_crate/src/lib.rs
index 067cf70..11e8f67 100644
--- a/rich_crate/src/lib.rs
+++ b/rich_crate/src/lib.rs
@@ -7,18 +7,18 @@ pub use crate::rich_crate::*;
mod rich_crate_version;
pub use crate::rich_crate_version::*;
+pub use cargo_toml::Manifest;
pub use render_readme::Markup;
pub use render_readme::Readme;
pub use repo_url::Repo;
pub use repo_url::RepoHost;
pub use repo_url::SimpleRepo;
-pub use cargo_toml::Manifest;
/// URL-like identifier of location where crate has been published + normalized crate name
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub enum Origin {
CratesIo(Box<str>),
- GitHub {repo: SimpleRepo, package: Box<str>},
+ GitHub { repo: SimpleRepo, package: Box<str> },
}
impl Origin {
@@ -27,7 +27,7 @@ impl Origin {
}
pub fn from_github(repo: SimpleRepo, package: impl Into<Box<str>>) -> Self {
- Origin::GitHub {repo, package: package.into()}
+ Origin::GitHub { repo, package: package.into() }
}
pub fn from_repo(r: &Repo, package: &str) -> Option<Self> {
@@ -57,14 +57,14 @@ impl Origin {
pub fn to_str(&self) -> String {
match *self {
Origin::CratesIo(ref s) => format!("crates.io:{}", s),
- Origin::GitHub {ref repo, ref package} => format!("github:{}/{}/{}", repo.owner, repo.repo, package),
+ Origin::GitHub { ref repo, ref package } => format!("github:{}/{}/{}", repo.owner, repo.repo, package),
}
}
pub fn short_crate_name(&self) -> &str {
match *self {
Origin::CratesIo(ref s) => s,
- Origin::GitHub {ref package, ..} => package,
+ Origin::GitHub { ref package, .. } => package,
}
}
}
@@ -79,8 +79,8 @@ fn roundtrip() {
#[test]
fn roundtrip_gh() {
- let o1 = Origin::from_github(SimpleRepo {owner: "foo".into(), repo: "bar".into()}, "baz");
- let o3 = Origin::from_github(SimpleRepo {owner: "foo".into(), repo: "bar".into()}, "other_package");
+ let o1 = Origin::from_github(SimpleRepo { owner: "foo".into(), repo: "bar".into() }, "baz");
+ let o3 = Origin::from_github(SimpleRepo { owner: "foo".into(), repo: "bar".into() }, "other_package");
let o2 = Origin::from_str(o1.to_str());
assert_eq!(o1, o2);
assert_ne!(o1, o3);
diff --git a/rich_crate/src/rich_crate_version.rs b/rich_crate/src/rich_crate_version.rs
index c693303..cae1644 100644
--- a/rich_crate/src/rich_crate_version.rs
+++ b/rich_crate/src/rich_crate_version.rs
@@ -37,8 +37,7 @@ pub enum Include {
///
/// Crates.rs uses this only for the latest version of a crate.
impl RichCrateVersion {
- pub fn new(origin: Origin, manifest: Manifest, derived: Derived) -> Self
- {
+ pub fn new(origin: Origin, manifest: Manifest, derived: Derived) -> Self {
let package = manifest.package.as_ref().expect("package");
Self {
origin,
diff --git a/server/src/main.rs b/server/src/main.rs
index 8a3e3c9..f1f8c9d 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -1,12 +1,12 @@
-use futures::future::FutureResult;
-use failure::ResultExt;
-use arc_swap::ArcSwap;
use actix_web::http::*;
use actix_web::*;
+use arc_swap::ArcSwap;
use categories::Category;
use categories::CATEGORIES;
use env_logger;
+use failure::ResultExt;
use front_end;
+use futures::future::FutureResult;
use futures::future::{self, Future};
use futures_cpupool::CpuPool;
use kitchen_sink;
@@ -16,12 +16,12 @@ use render_readme::{Highlighter, ImageOptimAPIFilter, Renderer};
use search_index::CrateSearchIndex;
use std::env;
use std::path::PathBuf;
-use std::sync::Arc;
use std::sync::atomic::{AtomicU32, Ordering};
+use std::sync::Arc;
use std::time::{Duration, SystemTime};
use tokio::prelude::FutureExt;
-use urlencoding::encode;
use urlencoding::decode;
+use urlencoding::encode;
mod writer;
use crate::writer::*;
@@ -301,20 +301,18 @@ fn with_file_cache<F>(cache_file: PathBuf, cache_time: u32, generate: impl FnOnc
}))
}
-fn render_crate_page(state: &AServerState, crate_name: String) -> impl Future<Item=Vec<u8>, Error=failure::Error> {
+fn render_crate_page(state: &AServerState, crate_name: String) -> impl Future<Item = Vec<u8>, Error = failure::Error> {
let state2 = Arc::clone(state);
- state
- .render_pool
- .spawn_fn(move || {
- let crates = state2.crates.load();
- crates.prewarm();
- let origin = Origin::from_crates_io_name(&crate_name);
- let all = crates.rich_crate(&origin)?;
- let ver = crates.rich_crate_version(&origin)?;
- let mut page: Vec<u8> = Vec::with_capacity(50000);
- front_end::render_crate_page(&mut page, &all, &ver, &crates, &state2.markup)?;
- Ok(page)
- })
+ state.render_pool.spawn_fn(move || {
+ let crates = state2.crates.load();
+ crates.prewarm();
+ let origin = Origin::from_crates_io_name(&crate_name);
+ let all = crates.rich_crate(&origin)?;
+ let ver = crates.rich_crate_version(&origin)?;
+ let mut page: Vec<u8> = Vec::with_capacity(50000);
+ front_end::render_crate_page(&mut page, &all, &ver, &crates, &state2.markup)?;
+ Ok(page)
+ })
}
fn handle_keyword(req: &HttpRequest<AServerState>) -> FutureResponse<HttpResponse> {
@@ -392,21 +390,21 @@ fn handle_search(req: &HttpRequest<AServerState>) -> Result<HttpResponse> {
let (mut w, page) = writer();
rayon::spawn(move || {
- let res = state.index.search(&query, 50, true)
- .map_err(From::from)
- .and_then(|results| {
- front_end::render_serp_page(&mut w, &query, &results, &state.markup)
- });
+ let res = state
+ .index
+ .search(&query, 50, true)
+ .map_err(From::from)
+ .and_then(|results| front_end::render_serp_page(&mut w, &query, &results, &state.markup));
if let Err(e) = res {
w.fail(e.into());
}
});
Ok(HttpResponse::Ok()
- .content_type("text/html;charset=UTF-8")
- .header("Cache-Control", "public, max-age=600, stale-while-revalidate=259200, stale-if-error=72000")
- .body(Body::Streaming(Box::new(page))))
- },
+ .content_type("text/html;charset=UTF-8")
+ .header("Cache-Control", "public, max-age=600, stale-while-revalidate=259200, stale-if-error=72000")
+ .body(Body::Streaming(Box::new(page))))
+ }
_ => Ok(HttpResponse::PermanentRedirect().header("Location", "/").finish()),
}
}
@@ -426,9 +424,9 @@ fn handle_sitemap(req: &HttpRequest<AServerState>) -> Result<HttpResponse> {
});
Ok(HttpResponse::Ok()
- .content_type("application/xml;charset=UTF-8")
- .header("Cache-Control", "public, max-age=259200, stale-while-revalidate=72000, stale-if-error=72000")
- .body(Body::Streaming(Box::new(page))))
+ .content_type("application/xml;charset=UTF-8")
+ .header("Cache-Control", "public, max-age=259200, stale-while-revalidate=72000, stale-if-error=72000")
+ .body(Body::Streaming(Box::new(page))))
}
fn handle_feed(req: &HttpRequest<AServerState>) -> FutureResponse<HttpResponse> {
@@ -458,8 +456,8 @@ fn handle_feed(req: &HttpRequest<AServerState>) -> FutureResponse<HttpResponse>
.responder()
}
-use header::HeaderValue;
use actix_web::middleware::{Middleware, Response};
+use header::HeaderValue;
struct StandardHeaders;
impl<S> Middleware<S> for StandardHeaders {
diff --git a/server/src/writer.rs b/server/src/writer.rs
index 1f9c343..7d3cc9a 100644
--- a/server/src/writer.rs
+++ b/server/src/writer.rs
@@ -1,6 +1,6 @@
-use futures::Stream;
use futures::sink::{Sink, Wait};
use futures::sync::mpsc;
+use futures::Stream;
use std::io;
pub struct Writer<T, E>(Wait<mpsc::Sender<Result<T, E>>>);
diff --git a/udedokei/src/lib.rs b/udedokei/src/lib.rs
index 7a5fcc5..df75b8b 100644
--- a/udedokei/src/lib.rs
+++ b/udedokei/src/lib.rs
@@ -1,6 +1,6 @@
use std::collections::HashMap;
-use std::path::PathBuf;
use std::path::Path;
+use std::path::PathBuf;
use serde_derive::*;
use tokei;
@@ -222,9 +222,7 @@ impl LanguageExt for Language {
impl Collect {
pub fn new() -> Self {
- Self {
- stats: Stats::default(),
- }
+ Self { stats: Stats::default() }
}
pub fn finish(self) -> Stats {
diff --git a/user_db/src/lib_user_db.rs b/user_db/src/lib_user_db.rs
index 9ac1ba8..b60ec75 100644
--- a/user_db/src/lib_user_db.rs
+++ b/user_db/src/lib_user_db.rs
@@ -3,9 +3,9 @@ use rusqlite::types::ToSql;
use github_info::User;
use github_info::UserType;
+use parking_lot::Mutex;
use rusqlite::*;
use std::path::Path;
-use parking_lot::Mutex;
type Result<T> = std::result::Result<T, failure::Error>;
mod schema;