style adaptations

these were introduced following suggestions from
https://crates.io/crate/clippy
This commit is contained in:
Andre Bogus 2016-05-03 00:57:41 +02:00
parent 0c89fafe20
commit dfd6a9b0d3
20 changed files with 105 additions and 127 deletions

View file

@ -17,7 +17,7 @@ pub fn create(rt: &Runtime) {
.and_then(|i| FromStr::from_str(i).ok()) .and_then(|i| FromStr::from_str(i).ok())
.unwrap_or(0); .unwrap_or(0);
match Counter::new(rt.store(), String::from(name.clone()), init) { match Counter::new(rt.store(), String::from(name), init) {
Err(e) => { Err(e) => {
warn!("Could not create Counter '{}' with initial value '{}'", name, init); warn!("Could not create Counter '{}' with initial value '{}'", name, init);
trace_error(&e); trace_error(&e);

View file

@ -51,7 +51,7 @@ pub fn interactive(rt: &Runtime) {
exit(1); exit(1);
} }
let cont = if input.len() > 0 { let cont = if !input.is_empty() {
let increment = match input.chars().next() { Some('-') => false, _ => true }; let increment = match input.chars().next() { Some('-') => false, _ => true };
input.chars().all(|chr| { input.chars().all(|chr| {
match pairs.get_mut(&chr) { match pairs.get_mut(&chr) {
@ -94,8 +94,8 @@ pub fn interactive(rt: &Runtime) {
fn has_quit_binding(pairs: &BTreeMap<char, Binding>) -> bool { fn has_quit_binding(pairs: &BTreeMap<char, Binding>) -> bool {
pairs.iter() pairs.iter()
.any(|(_, bind)| { .any(|(_, bind)| {
match bind { match *bind {
&Binding::Function(ref name, _) => name == "quit", Binding::Function(ref name, _) => name == "quit",
_ => false, _ => false,
} }
}) })
@ -109,8 +109,8 @@ enum Binding<'a> {
impl<'a> Display for Binding<'a> { impl<'a> Display for Binding<'a> {
fn fmt(&self, fmt: &mut Formatter) -> RResult<(), Error> { fn fmt(&self, fmt: &mut Formatter) -> RResult<(), Error> {
match self { match *self {
&Binding::Counter(ref c) => { Binding::Counter(ref c) => {
match c.name() { match c.name() {
Ok(name) => { Ok(name) => {
try!(write!(fmt, "{}", name)); try!(write!(fmt, "{}", name));
@ -122,7 +122,7 @@ impl<'a> Display for Binding<'a> {
}, },
} }
}, },
&Binding::Function(ref name, _) => write!(fmt, "{}()", name), Binding::Function(ref name, _) => write!(fmt, "{}()", name),
} }
} }

View file

@ -16,13 +16,10 @@ pub fn list(rt: &Runtime) {
if name.is_err() { if name.is_err() {
trace_error(&name.unwrap_err()); trace_error(&name.unwrap_err());
} else if value.is_err() {
trace_error(&value.unwrap_err());
} else { } else {
println!("{} - {}", name.unwrap(), value.unwrap());
if value.is_err() {
trace_error(&value.unwrap_err());
} else {
println!("{} - {}", name.unwrap(), value.unwrap());
}
} }
}) })
.map_err(|e| trace_error(&e)) .map_err(|e| trace_error(&e))

View file

@ -81,16 +81,14 @@ fn handle_internal_linking(rt: &Runtime) {
if cmd.is_present("list") { if cmd.is_present("list") {
debug!("List..."); debug!("List...");
for entry in cmd.value_of("list").unwrap().split(",") { for entry in cmd.value_of("list").unwrap().split(',') {
debug!("Listing for '{}'", entry); debug!("Listing for '{}'", entry);
match get_entry_by_name(rt, entry) { match get_entry_by_name(rt, entry) {
Ok(e) => { Ok(e) => {
e.get_internal_links() e.get_internal_links()
.map(|links| { .map(|links| {
let mut i = 0; for (i, link) in links.iter().map(|l| l.to_str()).filter_map(|x| x).enumerate() {
for link in links.iter().map(|l| l.to_str()).filter_map(|x| x) {
println!("{: <3}: {}", i, link); println!("{: <3}: {}", i, link);
i += 1;
} }
}) })
.map_err(|e| trace_error(&e)) .map_err(|e| trace_error(&e))
@ -275,7 +273,7 @@ fn set_links_for_entry(store: &Store, matches: &ArgMatches, entry: &mut FileLock
.value_of("links") .value_of("links")
.map(String::from) .map(String::from)
.unwrap() .unwrap()
.split(",") .split(',')
.map(|uri| { .map(|uri| {
match Url::parse(uri) { match Url::parse(uri) {
Err(e) => { Err(e) => {
@ -299,10 +297,8 @@ fn set_links_for_entry(store: &Store, matches: &ArgMatches, entry: &mut FileLock
fn list_links_for_entry(store: &Store, entry: &mut FileLockEntry) { fn list_links_for_entry(store: &Store, entry: &mut FileLockEntry) {
let res = entry.get_external_links(store) let res = entry.get_external_links(store)
.and_then(|links| { .and_then(|links| {
let mut i = 0; for (i, link) in links.enumerate() {
for link in links {
println!("{: <3}: {}", i, link); println!("{: <3}: {}", i, link);
i += 1;
} }
Ok(()) Ok(())
}); });

View file

@ -60,10 +60,9 @@ fn create(rt: &Runtime) {
.map_err(|e| trace_error(&e)) .map_err(|e| trace_error(&e))
.ok(); .ok();
if rt.cli().subcommand_matches("create").unwrap().is_present("edit") { if rt.cli().subcommand_matches("create").unwrap().is_present("edit") &&
if !edit_entry(rt, name) { !edit_entry(rt, name) {
exit(1); exit(1);
}
} }
} }

View file

@ -60,30 +60,24 @@ pub fn create(rt: &Runtime) {
fn create_from_cli_spec(rt: &Runtime, matches: &ArgMatches, path: &PathBuf) -> Result<()> { fn create_from_cli_spec(rt: &Runtime, matches: &ArgMatches, path: &PathBuf) -> Result<()> {
let content = matches.subcommand_matches("entry") let content = matches.subcommand_matches("entry")
.map(|entry_subcommand| { .map_or_else(|| {
debug!("Didn't find entry subcommand, getting raw content");
matches.value_of("from-raw")
.map_or_else(String::new, string_from_raw_src)
}, |entry_subcommand| {
debug!("Found entry subcommand, parsing content"); debug!("Found entry subcommand, parsing content");
entry_subcommand entry_subcommand
.value_of("content") .value_of("content")
.map(String::from) .map_or_else(|| {
.unwrap_or_else(|| { entry_subcommand.value_of("content-from")
entry_subcommand .map_or_else(String::new, string_from_raw_src)
.value_of("content-from") }, String::from)
.map(|src| string_from_raw_src(src))
.unwrap_or(String::new())
})
})
.unwrap_or_else(|| {
debug!("Didn't find entry subcommand, getting raw content");
matches.value_of("from-raw")
.map(|raw_src| string_from_raw_src(raw_src))
.unwrap_or(String::new())
}); });
debug!("Got content with len = {}", content.len()); debug!("Got content with len = {}", content.len());
let header = matches.subcommand_matches("entry") let header = matches.subcommand_matches("entry")
.map(|entry_matches| build_toml_header(entry_matches, EntryHeader::new())) .map_or_else(EntryHeader::new,
.unwrap_or(EntryHeader::new()); |entry_matches| build_toml_header(entry_matches, EntryHeader::new()));
create_with_content_and_header(rt, path, content, header) create_with_content_and_header(rt, path, content, header)
} }
@ -91,7 +85,7 @@ fn create_from_cli_spec(rt: &Runtime, matches: &ArgMatches, path: &PathBuf) -> R
fn create_from_source(rt: &Runtime, matches: &ArgMatches, path: &PathBuf) -> Result<()> { fn create_from_source(rt: &Runtime, matches: &ArgMatches, path: &PathBuf) -> Result<()> {
let content = matches let content = matches
.value_of("from-raw") .value_of("from-raw")
.ok_or(StoreError::new(StoreErrorKind::NoCommandlineCall, None)) .ok_or_else(|| StoreError::new(StoreErrorKind::NoCommandlineCall, None))
.map(|raw_src| string_from_raw_src(raw_src)); .map(|raw_src| string_from_raw_src(raw_src));
if content.is_err() { if content.is_err() {

View file

@ -3,20 +3,18 @@ use std::fmt::Error as FmtError;
use std::clone::Clone; use std::clone::Clone;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
/**
* Kind of store error
*/
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
/// Kind of store error
pub enum StoreErrorKind { pub enum StoreErrorKind {
BackendError, BackendError,
NoCommandlineCall, NoCommandlineCall,
// maybe more // maybe more
} }
fn store_error_type_as_str(e: &StoreErrorKind) -> &'static str { fn store_error_type_as_str(e: &StoreErrorKind) -> &'static str {
match e { match *e {
&StoreErrorKind::BackendError => "Backend Error", StoreErrorKind::BackendError => "Backend Error",
&StoreErrorKind::NoCommandlineCall => "No commandline call", StoreErrorKind::NoCommandlineCall => "No commandline call",
} }
} }
@ -37,9 +35,7 @@ pub struct StoreError {
impl StoreError { impl StoreError {
/** ///Build a new StoreError from an StoreErrorKind, optionally with cause
* Build a new StoreError from an StoreErrorKind, optionally with cause
*/
pub fn new(errtype: StoreErrorKind, cause: Option<Box<Error>>) pub fn new(errtype: StoreErrorKind, cause: Option<Box<Error>>)
-> StoreError -> StoreError
{ {
@ -49,11 +45,9 @@ impl StoreError {
} }
} }
/** /// Get the error type of this StoreError
* Get the error type of this StoreError
*/
pub fn err_type(&self) -> StoreErrorKind { pub fn err_type(&self) -> StoreErrorKind {
self.err_type.clone() self.err_type
} }
} }
@ -70,7 +64,7 @@ impl Display for StoreError {
impl Error for StoreError { impl Error for StoreError {
fn description(&self) -> &str { fn description(&self) -> &str {
store_error_type_as_str(&self.err_type.clone()) store_error_type_as_str(&self.err_type)
} }
fn cause(&self) -> Option<&Error> { fn cause(&self) -> Option<&Error> {

View file

@ -1,4 +1,5 @@
use std::collections::BTreeMap; use std::borrow::Cow;
use std::collections::btree_map::{BTreeMap, Entry};
use std::str::Split; use std::str::Split;
use clap::ArgMatches; use clap::ArgMatches;
@ -21,10 +22,10 @@ pub fn build_toml_header(matches: &ArgMatches, header: EntryHeader) -> EntryHead
for tpl in kvs { for tpl in kvs {
let (key, value) = tpl.into(); let (key, value) = tpl.into();
debug!("Splitting: {:?}", key); debug!("Splitting: {:?}", key);
let mut split = key.split("."); let mut split = key.split('.');
let current = split.next(); let current = split.next();
if current.is_some() { if current.is_some() {
insert_key_into(String::from(current.unwrap()), &mut split, value, &mut main); insert_key_into(String::from(current.unwrap()), &mut split, Cow::Owned(value), &mut main);
} }
} }
@ -36,9 +37,9 @@ pub fn build_toml_header(matches: &ArgMatches, header: EntryHeader) -> EntryHead
} }
} }
fn insert_key_into(current: String, fn insert_key_into<'a>(current: String,
rest_path: &mut Split<&str>, rest_path: &mut Split<char>,
value: String, value: Cow<'a, str>,
map: &mut BTreeMap<String, Value>) { map: &mut BTreeMap<String, Value>) {
let next = rest_path.next(); let next = rest_path.next();
@ -47,27 +48,30 @@ fn insert_key_into(current: String,
map.insert(current, parse_value(value)); map.insert(current, parse_value(value));
} else { } else {
debug!("Inserting into {:?} ... = {:?}", current, value); debug!("Inserting into {:?} ... = {:?}", current, value);
if map.contains_key(&current) { match map.entry(current) {
match map.get_mut(&current).unwrap() { Entry::Occupied(ref mut e) => {
&mut Value::Table(ref mut t) => { match *e.get_mut() {
insert_key_into(String::from(next.unwrap()), rest_path, value, t); Value::Table(ref mut t) => {
}, insert_key_into(String::from(next.unwrap()), rest_path, value, t);
_ => unreachable!(), },
_ => unreachable!(),
}
},
Entry::Vacant(v) => { v.insert(Value::Table( {
let mut submap = BTreeMap::new();
insert_key_into(String::from(next.unwrap()), rest_path, value, &mut submap);
debug!("Inserting submap = {:?}", submap);
submap }));
} }
} else {
let mut submap = BTreeMap::new();
insert_key_into(String::from(next.unwrap()), rest_path, value, &mut submap);
debug!("Inserting submap = {:?}", submap);
map.insert(current, Value::Table(submap));
} }
} }
} }
fn parse_value(value: String) -> Value { fn parse_value(value: Cow<str>) -> Value {
use std::str::FromStr; use std::str::FromStr;
fn is_ary(v: &String) -> bool { fn is_ary(v: &str) -> bool {
v.chars().next() == Some('[') && v.chars().last() == Some(']') && v.len() >= 3 v.starts_with('[') && v.ends_with(']') && v.len() >= 3
} }
if value == "true" { if value == "true" {
@ -79,7 +83,7 @@ fn parse_value(value: String) -> Value {
} else if is_ary(&value) { } else if is_ary(&value) {
debug!("Building Array out of: {:?}...", value); debug!("Building Array out of: {:?}...", value);
let sub = &value[1..(value.len()-1)]; let sub = &value[1..(value.len()-1)];
Value::Array(sub.split(",").map(|v| parse_value(String::from(v))).collect()) Value::Array(sub.split(',').map(|x| parse_value(Cow::from(x))).collect())
} else { } else {
FromStr::from_str(&value[..]) FromStr::from_str(&value[..])
.map(|i: i64| { .map(|i: i64| {
@ -94,7 +98,7 @@ fn parse_value(value: String) -> Value {
}) })
.unwrap_or_else(|_| { .unwrap_or_else(|_| {
debug!("Building String out of: {:?}...", value); debug!("Building String out of: {:?}...", value);
Value::String(value) Value::String(value.into_owned())
}) })
}) })
} }

View file

@ -77,8 +77,7 @@ fn alter(rt: &Runtime, id: &str, add: Option<&str>, rem: Option<&str>, set: Opti
.retrieve(path) .retrieve(path)
.map(|mut e| { .map(|mut e| {
add.map(|tags| { add.map(|tags| {
let tags = tags.split(","); for tag in tags.split(',') {
for tag in tags {
info!("Adding tag '{}'", tag); info!("Adding tag '{}'", tag);
if let Err(e) = e.add_tag(String::from(tag)) { if let Err(e) = e.add_tag(String::from(tag)) {
trace_error(&e); trace_error(&e);
@ -87,8 +86,7 @@ fn alter(rt: &Runtime, id: &str, add: Option<&str>, rem: Option<&str>, set: Opti
}); });
rem.map(|tags| { rem.map(|tags| {
let tags = tags.split(","); for tag in tags.split(',') {
for tag in tags {
info!("Removing tag '{}'", tag); info!("Removing tag '{}'", tag);
if let Err(e) = e.remove_tag(String::from(tag)) { if let Err(e) = e.remove_tag(String::from(tag)) {
trace_error(&e); trace_error(&e);
@ -98,7 +96,7 @@ fn alter(rt: &Runtime, id: &str, add: Option<&str>, rem: Option<&str>, set: Opti
set.map(|tags| { set.map(|tags| {
info!("Setting tags '{}'", tags); info!("Setting tags '{}'", tags);
let tags = tags.split(",").map(String::from).collect(); let tags = tags.split(',').map(String::from).collect();
if let Err(e) = e.set_tags(tags) { if let Err(e) = e.set_tags(tags) {
trace_error(&e); trace_error(&e);
} }

View file

@ -15,11 +15,11 @@ pub enum ViewErrorKind {
} }
fn view_error_type_as_str(e: &ViewErrorKind) -> &'static str { fn view_error_type_as_str(e: &ViewErrorKind) -> &'static str {
match e { match *e {
&ViewErrorKind::StoreError => "Store error", ViewErrorKind::StoreError => "Store error",
&ViewErrorKind::NoVersion => "No version specified", ViewErrorKind::NoVersion => "No version specified",
&ViewErrorKind::PatternError => "Error in Pattern", ViewErrorKind::PatternError => "Error in Pattern",
&ViewErrorKind::GlobBuildError => "Could not build glob() Argument", ViewErrorKind::GlobBuildError => "Could not build glob() Argument",
} }
} }
@ -59,7 +59,7 @@ impl ViewError {
* Get the error type of this ViewError * Get the error type of this ViewError
*/ */
pub fn err_type(&self) -> ViewErrorKind { pub fn err_type(&self) -> ViewErrorKind {
self.err_type.clone() self.err_type
} }
} }
@ -67,7 +67,7 @@ impl ViewError {
impl Display for ViewError { impl Display for ViewError {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "[{}]", view_error_type_as_str(&self.err_type.clone()))); try!(write!(fmt, "[{}]", view_error_type_as_str(&self.err_type)));
Ok(()) Ok(())
} }
@ -76,7 +76,7 @@ impl Display for ViewError {
impl Error for ViewError { impl Error for ViewError {
fn description(&self) -> &str { fn description(&self) -> &str {
view_error_type_as_str(&self.err_type.clone()) view_error_type_as_str(&self.err_type)
} }
fn cause(&self) -> Option<&Error> { fn cause(&self) -> Option<&Error> {

View file

@ -129,7 +129,7 @@ fn load_entry<'a>(id: &str,
let version = { let version = {
if version.is_none() { if version.is_none() {
let r = id.split("~").last(); let r = id.split('~').last();
if r.is_none() { if r.is_none() {
warn!("No version"); warn!("No version");
return Err(ViewError::new(ViewErrorKind::NoVersion, None)); return Err(ViewError::new(ViewErrorKind::NoVersion, None));
@ -144,7 +144,7 @@ fn load_entry<'a>(id: &str,
debug!("Building path from {:?} and {:?}", id, version); debug!("Building path from {:?} and {:?}", id, version);
let mut path = rt.store().path().clone(); let mut path = rt.store().path().clone();
if id.chars().next() == Some('/') { if id.starts_with('/') {
path.push(format!("{}~{}", &id[1..id.len()], version)); path.push(format!("{}~{}", &id[1..id.len()], version));
} else { } else {
path.push(format!("{}~{}", id, version)); path.push(format!("{}~{}", id, version));
@ -161,7 +161,7 @@ fn view_versions_of(id: &str, rt: &Runtime) -> Result<()> {
let mut path = rt.store().path().clone(); let mut path = rt.store().path().clone();
if id.chars().next() == Some('/') { if id.starts_with('/') {
path.push(format!("{}~*", &id[1..id.len()])); path.push(format!("{}~*", &id[1..id.len()]));
} else { } else {
path.push(format!("{}~*", id)); path.push(format!("{}~*", id));

View file

@ -144,12 +144,12 @@ impl<'a> Counter<'a> {
} }
trait FromStoreId { trait FromStoreId {
fn from_storeid<'a>(&'a Store, StoreId) -> Result<Counter<'a>>; fn from_storeid(&Store, StoreId) -> Result<Counter>;
} }
impl<'a> FromStoreId for Counter<'a> { impl<'a> FromStoreId for Counter<'a> {
fn from_storeid<'b>(store: &'b Store, id: StoreId) -> Result<Counter<'b>> { fn from_storeid(store: &Store, id: StoreId) -> Result<Counter> {
debug!("Loading counter from storeid: '{:?}'", id); debug!("Loading counter from storeid: '{:?}'", id);
match store.retrieve(id) { match store.retrieve(id) {
Err(e) => Err(CE::new(CEK::StoreReadError, Some(Box::new(e)))), Err(e) => Err(CE::new(CEK::StoreReadError, Some(Box::new(e)))),

View file

@ -1,6 +1,5 @@
use std::error::Error; use std::error::Error;
use std::fmt::Error as FmtError; use std::fmt::Error as FmtError;
use std::clone::Clone;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
/** /**
@ -15,11 +14,11 @@ pub enum CounterErrorKind {
} }
fn counter_error_type_as_str(e: &CounterErrorKind) -> &'static str { fn counter_error_type_as_str(e: &CounterErrorKind) -> &'static str {
match e { match *e {
&CounterErrorKind::StoreReadError => "Store read error", CounterErrorKind::StoreReadError => "Store read error",
&CounterErrorKind::StoreWriteError => "Store write error", CounterErrorKind::StoreWriteError => "Store write error",
&CounterErrorKind::HeaderTypeError => "Header type error", CounterErrorKind::HeaderTypeError => "Header type error",
&CounterErrorKind::HeaderFieldMissingError => "Header field missing error", CounterErrorKind::HeaderFieldMissingError => "Header field missing error",
} }
} }
@ -59,7 +58,7 @@ impl CounterError {
* Get the error type of this CounterError * Get the error type of this CounterError
*/ */
pub fn err_type(&self) -> CounterErrorKind { pub fn err_type(&self) -> CounterErrorKind {
self.err_type.clone() self.err_type
} }
} }
@ -67,7 +66,7 @@ impl CounterError {
impl Display for CounterError { impl Display for CounterError {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "[{}]", counter_error_type_as_str(&self.err_type.clone()))); try!(write!(fmt, "[{}]", counter_error_type_as_str(&self.err_type)));
Ok(()) Ok(())
} }
@ -76,7 +75,7 @@ impl Display for CounterError {
impl Error for CounterError { impl Error for CounterError {
fn description(&self) -> &str { fn description(&self) -> &str {
counter_error_type_as_str(&self.err_type.clone()) counter_error_type_as_str(&self.err_type)
} }
fn cause(&self) -> Option<&Error> { fn cause(&self) -> Option<&Error> {

View file

@ -14,15 +14,15 @@ struct EqGt {
impl Predicate for EqGt { impl Predicate for EqGt {
fn evaluate(&self, v: Value) -> bool { fn evaluate(&self, v: Value) -> bool {
match &self.comp { match self.comp {
&Value::Integer(i) => { Value::Integer(i) => {
match v { match v {
Value::Integer(j) => i > j, Value::Integer(j) => i > j,
Value::Float(f) => (i as f64) > f, Value::Float(f) => (i as f64) > f,
_ => false, _ => false,
} }
}, },
&Value::Float(f) => { Value::Float(f) => {
match v { match v {
Value::Integer(i) => f > (i as f64), Value::Integer(i) => f > (i as f64),
Value::Float(d) => f > d, Value::Float(d) => f > d,

View file

@ -27,11 +27,11 @@ impl Filter for FieldIsEmpty {
.map(|v| { .map(|v| {
match v { match v {
Some(Value::Array(a)) => a.is_empty(), Some(Value::Array(a)) => a.is_empty(),
Some(Value::Boolean(_)) => false,
Some(Value::Float(_)) => false,
Some(Value::Integer(_)) => false,
Some(Value::String(s)) => s.is_empty(), Some(Value::String(s)) => s.is_empty(),
Some(Value::Table(t)) => t.is_empty(), Some(Value::Table(t)) => t.is_empty(),
Some(Value::Boolean(_)) |
Some(Value::Float(_)) |
Some(Value::Integer(_)) => false,
_ => true, _ => true,
} }
}) })

View file

@ -21,11 +21,11 @@ impl Type {
fn matches(&self, v: &Value) -> bool { fn matches(&self, v: &Value) -> bool {
match (self, v) { match (self, v) {
(&Type::String, &Value::String(_)) => true, (&Type::String, &Value::String(_)) |
(&Type::Integer, &Value::Integer(_)) => true, (&Type::Integer, &Value::Integer(_)) |
(&Type::Float, &Value::Float(_)) => true, (&Type::Float, &Value::Float(_)) |
(&Type::Boolean, &Value::Boolean(_)) => true, (&Type::Boolean, &Value::Boolean(_)) |
(&Type::Array, &Value::Array(_)) => true, (&Type::Array, &Value::Array(_)) |
(&Type::Table, &Value::Table(_)) => true, (&Type::Table, &Value::Table(_)) => true,
_ => false, _ => false,
} }

View file

@ -14,15 +14,15 @@ struct EqLt {
impl Predicate for EqLt { impl Predicate for EqLt {
fn evaluate(&self, v: Value) -> bool { fn evaluate(&self, v: Value) -> bool {
match &self.comp { match self.comp {
&Value::Integer(i) => { Value::Integer(i) => {
match v { match v {
Value::Integer(j) => i < j, Value::Integer(j) => i < j,
Value::Float(f) => (i as f64) < f, Value::Float(f) => (i as f64) < f,
_ => false, _ => false,
} }
}, },
&Value::Float(f) => { Value::Float(f) => {
match v { match v {
Value::Integer(i) => f < (i as f64), Value::Integer(i) => f < (i as f64),
Value::Float(d) => f < d, Value::Float(d) => f < d,

View file

@ -23,7 +23,7 @@ impl Filter for VersionEq {
e.get_header() e.get_header()
.read("imag.version") .read("imag.version")
.map(|val| { .map(|val| {
val.map(|v| { val.map_or(false, |v| {
match v { match v {
Value::String(s) => { Value::String(s) => {
match Version::parse(&s[..]) { match Version::parse(&s[..]) {
@ -34,7 +34,6 @@ impl Filter for VersionEq {
_ => false, _ => false,
} }
}) })
.unwrap_or(false)
}) })
.unwrap_or(false) .unwrap_or(false)
} }

View file

@ -23,7 +23,7 @@ impl Filter for VersionGt {
e.get_header() e.get_header()
.read("imag.version") .read("imag.version")
.map(|val| { .map(|val| {
val.map(|v| { val.map_or(false, |v| {
match v { match v {
Value::String(s) => { Value::String(s) => {
match Version::parse(&s[..]) { match Version::parse(&s[..]) {
@ -34,7 +34,6 @@ impl Filter for VersionGt {
_ => false, _ => false,
} }
}) })
.unwrap_or(false)
}) })
.unwrap_or(false) .unwrap_or(false)
} }

View file

@ -23,7 +23,7 @@ impl Filter for VersionLt {
e.get_header() e.get_header()
.read("imag.version") .read("imag.version")
.map(|val| { .map(|val| {
val.map(|v| { val.map_or(false, |v| {
match v { match v {
Value::String(s) => { Value::String(s) => {
match Version::parse(&s[..]) { match Version::parse(&s[..]) {
@ -34,7 +34,6 @@ impl Filter for VersionLt {
_ => false, _ => false,
} }
}) })
.unwrap_or(false)
}) })
.unwrap_or(false) .unwrap_or(false)
} }