mirror of
https://github.com/deps-rs/deps.rs.git
synced 2024-11-22 18:36:30 +00:00
simplify latest crate search
This commit is contained in:
parent
37a11c17b5
commit
c7bc04efc1
2 changed files with 7 additions and 12 deletions
|
@ -147,20 +147,14 @@ impl Engine {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_latest_crate_release(&self, name: CrateName, req: Option<VersionReq>) ->
|
pub fn find_latest_crate_release(&self, name: CrateName, req: VersionReq) ->
|
||||||
impl Future<Item=Option<CrateRelease>, Error=Error>
|
impl Future<Item=Option<CrateRelease>, Error=Error>
|
||||||
{
|
{
|
||||||
self.query_crate.call(name).from_err().map(move |query_response| {
|
self.query_crate.call(name).from_err().map(move |query_response| {
|
||||||
if let Some(vreq) = req {
|
|
||||||
query_response.releases.iter()
|
query_response.releases.iter()
|
||||||
.filter(|release| vreq.matches(&release.version))
|
.filter(|release| req.matches(&release.version))
|
||||||
.max_by(|r1, r2| r1.version.cmp(&r2.version))
|
.max_by(|r1, r2| r1.version.cmp(&r2.version))
|
||||||
.cloned()
|
.cloned()
|
||||||
} else {
|
|
||||||
query_response.releases.iter()
|
|
||||||
.max_by(|r1, r2| r1.version.cmp(&r2.version))
|
|
||||||
.cloned()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ use futures::{Future, IntoFuture, future};
|
||||||
use hyper::{Error as HyperError, Method, Request, Response, StatusCode};
|
use hyper::{Error as HyperError, Method, Request, Response, StatusCode};
|
||||||
use hyper::header::{ContentType, Location};
|
use hyper::header::{ContentType, Location};
|
||||||
use route_recognizer::{Params, Router};
|
use route_recognizer::{Params, Router};
|
||||||
|
use semver::VersionReq;
|
||||||
use slog::Logger;
|
use slog::Logger;
|
||||||
use tokio_service::Service;
|
use tokio_service::Service;
|
||||||
|
|
||||||
|
@ -183,7 +184,7 @@ impl Server {
|
||||||
future::Either::A(future::ok(response))
|
future::Either::A(future::ok(response))
|
||||||
},
|
},
|
||||||
Ok(crate_name) => {
|
Ok(crate_name) => {
|
||||||
future::Either::B(engine.find_latest_crate_release(crate_name, None).then(move |release_result| {
|
future::Either::B(engine.find_latest_crate_release(crate_name, VersionReq::any()).then(move |release_result| {
|
||||||
match release_result {
|
match release_result {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!(logger, "error: {}", err);
|
error!(logger, "error: {}", err);
|
||||||
|
|
Loading…
Reference in a new issue