From c7bc04efc19d228286086a35d8f7112b9bd41a6b Mon Sep 17 00:00:00 2001 From: Sam Rijs Date: Sat, 17 Feb 2018 14:59:54 +1100 Subject: [PATCH] simplify latest crate search --- src/engine/mod.rs | 16 +++++----------- src/server/mod.rs | 3 ++- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/engine/mod.rs b/src/engine/mod.rs index 7490204..52cc80b 100644 --- a/src/engine/mod.rs +++ b/src/engine/mod.rs @@ -147,20 +147,14 @@ impl Engine { }) } - pub fn find_latest_crate_release(&self, name: CrateName, req: Option) -> + pub fn find_latest_crate_release(&self, name: CrateName, req: VersionReq) -> impl Future, Error=Error> { self.query_crate.call(name).from_err().map(move |query_response| { - if let Some(vreq) = req { - query_response.releases.iter() - .filter(|release| vreq.matches(&release.version)) - .max_by(|r1, r2| r1.version.cmp(&r2.version)) - .cloned() - } else { - query_response.releases.iter() - .max_by(|r1, r2| r1.version.cmp(&r2.version)) - .cloned() - } + query_response.releases.iter() + .filter(|release| req.matches(&release.version)) + .max_by(|r1, r2| r1.version.cmp(&r2.version)) + .cloned() }) } diff --git a/src/server/mod.rs b/src/server/mod.rs index a4ddd82..9d52d56 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -5,6 +5,7 @@ use futures::{Future, IntoFuture, future}; use hyper::{Error as HyperError, Method, Request, Response, StatusCode}; use hyper::header::{ContentType, Location}; use route_recognizer::{Params, Router}; +use semver::VersionReq; use slog::Logger; use tokio_service::Service; @@ -183,7 +184,7 @@ impl Server { future::Either::A(future::ok(response)) }, 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 { Err(err) => { error!(logger, "error: {}", err);