mirror of
https://github.com/deps-rs/deps.rs.git
synced 2024-11-22 02:16:30 +00:00
fix clippy lints (#56)
This commit is contained in:
parent
871e9acd74
commit
66fd685062
15 changed files with 78 additions and 103 deletions
|
@ -46,7 +46,7 @@ pub async fn analyze_dependencies(
|
|||
let deps_iter = main_deps.chain(dev_deps).chain(build_deps);
|
||||
let mut releases = engine.fetch_releases(deps_iter);
|
||||
|
||||
for release in releases.next().await {
|
||||
while let Some(release) = releases.next().await {
|
||||
let release = release?;
|
||||
analyzer.process(release)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::{future::Future, mem, pin::Pin, task::Context, task::Poll};
|
||||
|
||||
use anyhow::Error;
|
||||
use futures::{ready, Stream};
|
||||
use futures::{future::BoxFuture, ready, Stream};
|
||||
use futures::{stream::FuturesOrdered, FutureExt};
|
||||
use relative_path::RelativePathBuf;
|
||||
|
||||
|
@ -17,9 +17,7 @@ pub struct CrawlManifestFuture {
|
|||
engine: Engine,
|
||||
crawler: ManifestCrawler,
|
||||
#[pin]
|
||||
futures: FuturesOrdered<
|
||||
Pin<Box<dyn Future<Output = Result<(RelativePathBuf, String), Error>> + Send>>,
|
||||
>,
|
||||
futures: FuturesOrdered<BoxFuture<'static, Result<(RelativePathBuf, String), Error>>>,
|
||||
}
|
||||
|
||||
impl CrawlManifestFuture {
|
||||
|
@ -63,7 +61,7 @@ impl Future for CrawlManifestFuture {
|
|||
let future: Pin<Box<dyn Future<Output = _> + Send>> = Box::pin(
|
||||
self.engine
|
||||
.retrieve_manifest_at_path(&self.repo_path, &path)
|
||||
.map(move |contents| contents.map(|c| ((path, c)))),
|
||||
.map(move |contents| contents.map(|c| (path, c))),
|
||||
);
|
||||
self.futures.push(future);
|
||||
}
|
||||
|
@ -71,7 +69,7 @@ impl Future for CrawlManifestFuture {
|
|||
self.poll(cx)
|
||||
}
|
||||
|
||||
Some(Err(err)) => Poll::Ready(Err(err.into())),
|
||||
Some(Err(err)) => Poll::Ready(Err(err)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ impl ManifestCrawler {
|
|||
.chain(deps.dev.iter())
|
||||
.chain(deps.build.iter())
|
||||
{
|
||||
if let &CrateDep::Internal(ref path) = dep {
|
||||
if let CrateDep::Internal(ref path) = dep {
|
||||
self.register_interest(base_path, path, output);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ impl Service<Request<Body>> for ServiceHttpClient {
|
|||
type Future = ResponseFuture;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
self.0.poll_ready(cx).map_err(|err| err.into())
|
||||
self.0.poll_ready(cx)
|
||||
}
|
||||
|
||||
fn call(&mut self, req: Request<Body>) -> Self::Future {
|
||||
|
@ -97,7 +97,7 @@ impl Engine {
|
|||
);
|
||||
|
||||
Engine {
|
||||
client: client.clone(),
|
||||
client,
|
||||
logger,
|
||||
metrics,
|
||||
query_crate: Arc::new(Mutex::new(query_crate)),
|
||||
|
@ -156,7 +156,7 @@ impl Engine {
|
|||
pub async fn get_popular_crates(&self) -> Result<Vec<CratePath>, Error> {
|
||||
let crates = self.get_popular_crates.lock().unwrap().call(());
|
||||
let crates = crates.await?;
|
||||
Ok(crates.clone())
|
||||
Ok(crates)
|
||||
}
|
||||
|
||||
pub async fn analyze_repo_dependencies(
|
||||
|
@ -264,7 +264,7 @@ impl Engine {
|
|||
.lock()
|
||||
.unwrap()
|
||||
.call(name)
|
||||
.map(|resp| resp.map(|r| r.releases.clone()))
|
||||
.map(|resp| resp.map(|r| r.releases))
|
||||
})
|
||||
.collect::<FuturesUnordered<_>>()
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
use std::pin::Pin;
|
||||
use std::{future::Future, task::Poll};
|
||||
use std::{str, task::Context};
|
||||
use std::{str, task::Context, task::Poll};
|
||||
|
||||
use anyhow::{anyhow, Error};
|
||||
use futures::{
|
||||
future::{err, ok, ready},
|
||||
future::{err, ok, ready, BoxFuture},
|
||||
TryFutureExt,
|
||||
};
|
||||
use hyper::{
|
||||
|
@ -44,12 +42,7 @@ fn convert_pkgs(
|
|||
.map(|package| {
|
||||
let mut deps = CrateDeps::default();
|
||||
for dep in package.deps {
|
||||
match dep
|
||||
.kind
|
||||
.map(|k| k.clone())
|
||||
.unwrap_or_else(|| "normal".into())
|
||||
.as_ref()
|
||||
{
|
||||
match dep.kind.unwrap_or_else(|| "normal".into()).as_ref() {
|
||||
"normal" => deps
|
||||
.main
|
||||
.insert(dep.name.parse()?, CrateDep::External(dep.req)),
|
||||
|
@ -62,13 +55,13 @@ fn convert_pkgs(
|
|||
Ok(CrateRelease {
|
||||
name: name.clone(),
|
||||
version: package.vers,
|
||||
deps: deps,
|
||||
deps,
|
||||
yanked: package.yanked,
|
||||
})
|
||||
})
|
||||
.collect::<Result<_, Error>>()?;
|
||||
|
||||
Ok(QueryCrateResponse { releases: releases })
|
||||
Ok(QueryCrateResponse { releases })
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -86,7 +79,7 @@ where
|
|||
{
|
||||
type Response = QueryCrateResponse;
|
||||
type Error = Error;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
|
||||
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
self.0.poll_ready(cx).map_err(|err| err.into())
|
||||
|
@ -175,7 +168,7 @@ where
|
|||
{
|
||||
type Response = Vec<CratePath>;
|
||||
type Error = Error;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
|
||||
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
self.0.poll_ready(cx).map_err(|err| err.into())
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use std::{future::Future, pin::Pin, task::Context, task::Poll};
|
||||
use std::{task::Context, task::Poll};
|
||||
|
||||
use anyhow::{anyhow, Error};
|
||||
use futures::{
|
||||
future::{err, ok, ready},
|
||||
future::{err, ok, ready, BoxFuture},
|
||||
TryFutureExt,
|
||||
};
|
||||
use hyper::{
|
||||
|
@ -12,7 +12,7 @@ use serde::Deserialize;
|
|||
|
||||
use crate::models::repo::{RepoPath, Repository};
|
||||
|
||||
const GITHUB_API_BASE_URI: &'static str = "https://api.github.com";
|
||||
const GITHUB_API_BASE_URI: &str = "https://api.github.com";
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct GithubSearchResponse {
|
||||
|
@ -41,7 +41,7 @@ where
|
|||
{
|
||||
type Response = Vec<Repository>;
|
||||
type Error = Error;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
|
||||
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
self.0.poll_ready(cx).map_err(|err| err.into())
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
use std::{future::Future, task::Poll};
|
||||
use std::{pin::Pin, task::Context};
|
||||
use std::{task::Context, task::Poll};
|
||||
|
||||
use anyhow::{anyhow, Error};
|
||||
use futures::{
|
||||
future::{err, ok, ready},
|
||||
future::{err, ok, ready, BoxFuture},
|
||||
TryFutureExt,
|
||||
};
|
||||
use hyper::{
|
||||
|
@ -27,7 +26,7 @@ where
|
|||
{
|
||||
type Response = String;
|
||||
type Error = Error;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
|
||||
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
self.0.poll_ready(cx).map_err(|err| err.into())
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::{pin::Pin, sync::Arc, task::Context, task::Poll};
|
||||
use std::{sync::Arc, task::Context, task::Poll};
|
||||
|
||||
use anyhow::Error;
|
||||
use futures::{future::ready, Future};
|
||||
use futures::{future::ready, future::BoxFuture};
|
||||
use hyper::{service::Service, Body, Error as HyperError, Request, Response};
|
||||
use rustsec::database::Database;
|
||||
|
||||
|
@ -15,7 +15,7 @@ where
|
|||
{
|
||||
type Response = Arc<Database>;
|
||||
type Error = Error;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
|
||||
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
|
||||
|
||||
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
// TODO: should be this when async client is used again
|
||||
|
@ -28,9 +28,7 @@ where
|
|||
let _service = self.0.clone();
|
||||
|
||||
Box::pin(ready(
|
||||
rustsec::Database::fetch()
|
||||
.map(|db| Arc::new(db))
|
||||
.map_err(|err| err.into()),
|
||||
rustsec::Database::fetch().map(Arc::new).map_err(Into::into),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,11 +73,7 @@ pub enum CrateDep {
|
|||
|
||||
impl CrateDep {
|
||||
pub fn is_external(&self) -> bool {
|
||||
if let &CrateDep::External(_) = self {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
matches!(self, CrateDep::External(_))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,7 +120,7 @@ impl AnalyzedDependencies {
|
|||
.main
|
||||
.iter()
|
||||
.filter_map(|(name, dep)| {
|
||||
if let &CrateDep::External(ref req) = dep {
|
||||
if let CrateDep::External(ref req) = dep {
|
||||
Some((name.clone(), AnalyzedDependency::new(req.clone())))
|
||||
} else {
|
||||
None
|
||||
|
@ -135,7 +131,7 @@ impl AnalyzedDependencies {
|
|||
.dev
|
||||
.iter()
|
||||
.filter_map(|(name, dep)| {
|
||||
if let &CrateDep::External(ref req) = dep {
|
||||
if let CrateDep::External(ref req) = dep {
|
||||
Some((name.clone(), AnalyzedDependency::new(req.clone())))
|
||||
} else {
|
||||
None
|
||||
|
@ -146,7 +142,7 @@ impl AnalyzedDependencies {
|
|||
.build
|
||||
.iter()
|
||||
.filter_map(|(name, dep)| {
|
||||
if let &CrateDep::External(ref req) = dep {
|
||||
if let CrateDep::External(ref req) = dep {
|
||||
Some((name.clone(), AnalyzedDependency::new(req.clone())))
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -50,9 +50,9 @@ pub enum RepoSite {
|
|||
impl RepoSite {
|
||||
pub fn to_base_uri(&self) -> &'static str {
|
||||
match self {
|
||||
&RepoSite::Github => "https://github.com",
|
||||
&RepoSite::Gitlab => "https://gitlab.com",
|
||||
&RepoSite::Bitbucket => "https://bitbucket.org",
|
||||
RepoSite::Github => "https://github.com",
|
||||
RepoSite::Gitlab => "https://gitlab.com",
|
||||
RepoSite::Bitbucket => "https://bitbucket.org",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,9 +88,9 @@ impl FromStr for RepoSite {
|
|||
impl AsRef<str> for RepoSite {
|
||||
fn as_ref(&self) -> &str {
|
||||
match self {
|
||||
&RepoSite::Github => "github",
|
||||
&RepoSite::Gitlab => "gitlab",
|
||||
&RepoSite::Bitbucket => "bitbucket",
|
||||
RepoSite::Github => "github",
|
||||
RepoSite::Gitlab => "gitlab",
|
||||
RepoSite::Bitbucket => "bitbucket",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,35 +51,30 @@ fn convert_dependency(
|
|||
cargo_dep: (String, CargoTomlDependency),
|
||||
) -> Option<Result<(CrateName, CrateDep), Error>> {
|
||||
match cargo_dep {
|
||||
(name, CargoTomlDependency::Simple(string)) => Some(
|
||||
name.parse::<CrateName>()
|
||||
.map_err(|err| err.into())
|
||||
.and_then(|parsed_name| {
|
||||
string
|
||||
.parse::<VersionReq>()
|
||||
.map_err(|err| err.into())
|
||||
.map(|version| (parsed_name, CrateDep::External(version)))
|
||||
}),
|
||||
),
|
||||
(name, CargoTomlDependency::Simple(string)) => {
|
||||
Some(name.parse::<CrateName>().and_then(|parsed_name| {
|
||||
string
|
||||
.parse::<VersionReq>()
|
||||
.map_err(|err| err.into())
|
||||
.map(|version| (parsed_name, CrateDep::External(version)))
|
||||
}))
|
||||
}
|
||||
(name, CargoTomlDependency::Complex(cplx)) => {
|
||||
if cplx.git.is_some() {
|
||||
None
|
||||
} else if cplx.path.is_some() {
|
||||
cplx.path.map(|path| {
|
||||
name.parse::<CrateName>()
|
||||
.map_err(|err| err.into())
|
||||
.map(|parsed_name| (parsed_name, CrateDep::Internal(path)))
|
||||
})
|
||||
} else {
|
||||
cplx.version.map(|string| {
|
||||
name.parse::<CrateName>()
|
||||
.map_err(|err| err.into())
|
||||
.and_then(|parsed_name| {
|
||||
string
|
||||
.parse::<VersionReq>()
|
||||
.map_err(|err| err.into())
|
||||
.map(|version| (parsed_name, CrateDep::External(version)))
|
||||
})
|
||||
name.parse::<CrateName>().and_then(|parsed_name| {
|
||||
string
|
||||
.parse::<VersionReq>()
|
||||
.map_err(|err| err.into())
|
||||
.map(|version| (parsed_name, CrateDep::External(version)))
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,36 +86,33 @@ impl App {
|
|||
.new(o!("http_path" => req.uri().path().to_owned()));
|
||||
|
||||
if let Ok(route_match) = self.router.recognize(req.uri().path()) {
|
||||
match route_match.handler {
|
||||
&Route::Index => {
|
||||
if *req.method() == Method::GET {
|
||||
return self.index(req, route_match.params, logger).await;
|
||||
}
|
||||
match (req.method(), route_match.handler) {
|
||||
(&Method::GET, Route::Index) => {
|
||||
return self.index(req, route_match.params, logger).await;
|
||||
}
|
||||
&Route::RepoStatus(format) => {
|
||||
if *req.method() == Method::GET {
|
||||
return self
|
||||
.repo_status(req, route_match.params, logger, format)
|
||||
.await;
|
||||
}
|
||||
|
||||
(&Method::GET, Route::RepoStatus(format)) => {
|
||||
return self
|
||||
.repo_status(req, route_match.params, logger, *format)
|
||||
.await;
|
||||
}
|
||||
&Route::CrateStatus(format) => {
|
||||
if *req.method() == Method::GET {
|
||||
return self
|
||||
.crate_status(req, route_match.params, logger, format)
|
||||
.await;
|
||||
}
|
||||
|
||||
(&Method::GET, Route::CrateStatus(format)) => {
|
||||
return self
|
||||
.crate_status(req, route_match.params, logger, *format)
|
||||
.await;
|
||||
}
|
||||
&Route::CrateRedirect => {
|
||||
if *req.method() == Method::GET {
|
||||
return self.crate_redirect(req, route_match.params, logger).await;
|
||||
}
|
||||
|
||||
(&Method::GET, Route::CrateRedirect) => {
|
||||
return self.crate_redirect(req, route_match.params, logger).await;
|
||||
}
|
||||
&Route::Static(file) => {
|
||||
if *req.method() == Method::GET {
|
||||
return Ok(App::static_file(file));
|
||||
}
|
||||
|
||||
(&Method::GET, Route::Static(file)) => {
|
||||
return Ok(App::static_file(*file));
|
||||
}
|
||||
|
||||
// fall through to 404
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ fn popular_table(popular_repos: Vec<Repository>, popular_crates: Vec<CratePath>)
|
|||
tr {
|
||||
td {
|
||||
a href=(format!("{}/crate/{}/{}", &super::SELF_BASE_URL as &str, crate_path.name.as_ref(), crate_path.version)) {
|
||||
(format!("{}", crate_path.name.as_ref()))
|
||||
(crate_path.name.as_ref().to_string())
|
||||
}
|
||||
}
|
||||
td class="has-text-right" {
|
||||
|
|
|
@ -48,8 +48,7 @@ fn render_navbar() -> Markup {
|
|||
}
|
||||
|
||||
fn render_footer(duration: Option<Duration>) -> Markup {
|
||||
let duration_millis =
|
||||
duration.map(|d| d.as_secs() * 1000 + (d.subsec_nanos() / 1000 / 1000) as u64);
|
||||
let duration_millis = duration.map(|d| d.as_secs() * 1000 + (d.subsec_millis()) as u64);
|
||||
|
||||
html! {
|
||||
footer class="footer" {
|
||||
|
|
|
@ -43,7 +43,7 @@ where
|
|||
pub fn new(service: S, duration: Duration, capacity: usize) -> Cache<S, Req> {
|
||||
Cache {
|
||||
inner: service,
|
||||
duration: duration,
|
||||
duration,
|
||||
cache: Mutex::new(LruCache::new(capacity)),
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ where
|
|||
// }
|
||||
// }
|
||||
|
||||
self.inner.call(req.clone())
|
||||
self.inner.call(req)
|
||||
// .and_then(|response| {
|
||||
// // cache.insert(req, (now + self.duration, response.clone()));
|
||||
// ok(response)
|
||||
|
|
Loading…
Reference in a new issue