style adaptations
these were introduced following suggestions from https://crates.io/crate/clippy
This commit is contained in:
parent
0c89fafe20
commit
dfd6a9b0d3
20 changed files with 105 additions and 127 deletions
|
@ -17,7 +17,7 @@ pub fn create(rt: &Runtime) {
|
|||
.and_then(|i| FromStr::from_str(i).ok())
|
||||
.unwrap_or(0);
|
||||
|
||||
match Counter::new(rt.store(), String::from(name.clone()), init) {
|
||||
match Counter::new(rt.store(), String::from(name), init) {
|
||||
Err(e) => {
|
||||
warn!("Could not create Counter '{}' with initial value '{}'", name, init);
|
||||
trace_error(&e);
|
||||
|
|
|
@ -51,7 +51,7 @@ pub fn interactive(rt: &Runtime) {
|
|||
exit(1);
|
||||
}
|
||||
|
||||
let cont = if input.len() > 0 {
|
||||
let cont = if !input.is_empty() {
|
||||
let increment = match input.chars().next() { Some('-') => false, _ => true };
|
||||
input.chars().all(|chr| {
|
||||
match pairs.get_mut(&chr) {
|
||||
|
@ -94,8 +94,8 @@ pub fn interactive(rt: &Runtime) {
|
|||
fn has_quit_binding(pairs: &BTreeMap<char, Binding>) -> bool {
|
||||
pairs.iter()
|
||||
.any(|(_, bind)| {
|
||||
match bind {
|
||||
&Binding::Function(ref name, _) => name == "quit",
|
||||
match *bind {
|
||||
Binding::Function(ref name, _) => name == "quit",
|
||||
_ => false,
|
||||
}
|
||||
})
|
||||
|
@ -109,8 +109,8 @@ enum Binding<'a> {
|
|||
impl<'a> Display for Binding<'a> {
|
||||
|
||||
fn fmt(&self, fmt: &mut Formatter) -> RResult<(), Error> {
|
||||
match self {
|
||||
&Binding::Counter(ref c) => {
|
||||
match *self {
|
||||
Binding::Counter(ref c) => {
|
||||
match c.name() {
|
||||
Ok(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),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,14 +16,11 @@ pub fn list(rt: &Runtime) {
|
|||
|
||||
if name.is_err() {
|
||||
trace_error(&name.unwrap_err());
|
||||
} else {
|
||||
|
||||
if value.is_err() {
|
||||
} else if value.is_err() {
|
||||
trace_error(&value.unwrap_err());
|
||||
} else {
|
||||
println!("{} - {}", name.unwrap(), value.unwrap());
|
||||
}
|
||||
}
|
||||
})
|
||||
.map_err(|e| trace_error(&e))
|
||||
.ok();
|
||||
|
|
|
@ -81,16 +81,14 @@ fn handle_internal_linking(rt: &Runtime) {
|
|||
|
||||
if cmd.is_present("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);
|
||||
match get_entry_by_name(rt, entry) {
|
||||
Ok(e) => {
|
||||
e.get_internal_links()
|
||||
.map(|links| {
|
||||
let mut i = 0;
|
||||
for link in links.iter().map(|l| l.to_str()).filter_map(|x| x) {
|
||||
for (i, link) in links.iter().map(|l| l.to_str()).filter_map(|x| x).enumerate() {
|
||||
println!("{: <3}: {}", i, link);
|
||||
i += 1;
|
||||
}
|
||||
})
|
||||
.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")
|
||||
.map(String::from)
|
||||
.unwrap()
|
||||
.split(",")
|
||||
.split(',')
|
||||
.map(|uri| {
|
||||
match Url::parse(uri) {
|
||||
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) {
|
||||
let res = entry.get_external_links(store)
|
||||
.and_then(|links| {
|
||||
let mut i = 0;
|
||||
for link in links {
|
||||
for (i, link) in links.enumerate() {
|
||||
println!("{: <3}: {}", i, link);
|
||||
i += 1;
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
|
|
|
@ -60,11 +60,10 @@ fn create(rt: &Runtime) {
|
|||
.map_err(|e| trace_error(&e))
|
||||
.ok();
|
||||
|
||||
if rt.cli().subcommand_matches("create").unwrap().is_present("edit") {
|
||||
if !edit_entry(rt, name) {
|
||||
if rt.cli().subcommand_matches("create").unwrap().is_present("edit") &&
|
||||
!edit_entry(rt, name) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn delete(rt: &Runtime) {
|
||||
|
|
|
@ -60,30 +60,24 @@ pub fn create(rt: &Runtime) {
|
|||
|
||||
fn create_from_cli_spec(rt: &Runtime, matches: &ArgMatches, path: &PathBuf) -> Result<()> {
|
||||
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");
|
||||
entry_subcommand
|
||||
.value_of("content")
|
||||
.map(String::from)
|
||||
.unwrap_or_else(|| {
|
||||
entry_subcommand
|
||||
.value_of("content-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())
|
||||
.map_or_else(|| {
|
||||
entry_subcommand.value_of("content-from")
|
||||
.map_or_else(String::new, string_from_raw_src)
|
||||
}, String::from)
|
||||
});
|
||||
|
||||
debug!("Got content with len = {}", content.len());
|
||||
|
||||
let header = matches.subcommand_matches("entry")
|
||||
.map(|entry_matches| build_toml_header(entry_matches, EntryHeader::new()))
|
||||
.unwrap_or(EntryHeader::new());
|
||||
.map_or_else(EntryHeader::new,
|
||||
|entry_matches| build_toml_header(entry_matches, EntryHeader::new()));
|
||||
|
||||
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<()> {
|
||||
let content = matches
|
||||
.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));
|
||||
|
||||
if content.is_err() {
|
||||
|
|
|
@ -3,10 +3,8 @@ use std::fmt::Error as FmtError;
|
|||
use std::clone::Clone;
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
/**
|
||||
* Kind of store error
|
||||
*/
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
/// Kind of store error
|
||||
pub enum StoreErrorKind {
|
||||
BackendError,
|
||||
NoCommandlineCall,
|
||||
|
@ -14,9 +12,9 @@ pub enum StoreErrorKind {
|
|||
}
|
||||
|
||||
fn store_error_type_as_str(e: &StoreErrorKind) -> &'static str {
|
||||
match e {
|
||||
&StoreErrorKind::BackendError => "Backend Error",
|
||||
&StoreErrorKind::NoCommandlineCall => "No commandline call",
|
||||
match *e {
|
||||
StoreErrorKind::BackendError => "Backend Error",
|
||||
StoreErrorKind::NoCommandlineCall => "No commandline call",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,9 +35,7 @@ pub struct 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>>)
|
||||
-> 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 {
|
||||
self.err_type.clone()
|
||||
self.err_type
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -70,7 +64,7 @@ impl Display for StoreError {
|
|||
impl Error for StoreError {
|
||||
|
||||
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> {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use std::collections::BTreeMap;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::btree_map::{BTreeMap, Entry};
|
||||
use std::str::Split;
|
||||
|
||||
use clap::ArgMatches;
|
||||
|
@ -21,10 +22,10 @@ pub fn build_toml_header(matches: &ArgMatches, header: EntryHeader) -> EntryHead
|
|||
for tpl in kvs {
|
||||
let (key, value) = tpl.into();
|
||||
debug!("Splitting: {:?}", key);
|
||||
let mut split = key.split(".");
|
||||
let mut split = key.split('.');
|
||||
let current = split.next();
|
||||
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,
|
||||
rest_path: &mut Split<&str>,
|
||||
value: String,
|
||||
fn insert_key_into<'a>(current: String,
|
||||
rest_path: &mut Split<char>,
|
||||
value: Cow<'a, str>,
|
||||
map: &mut BTreeMap<String, Value>) {
|
||||
let next = rest_path.next();
|
||||
|
||||
|
@ -47,27 +48,30 @@ fn insert_key_into(current: String,
|
|||
map.insert(current, parse_value(value));
|
||||
} else {
|
||||
debug!("Inserting into {:?} ... = {:?}", current, value);
|
||||
if map.contains_key(¤t) {
|
||||
match map.get_mut(¤t).unwrap() {
|
||||
&mut Value::Table(ref mut t) => {
|
||||
match map.entry(current) {
|
||||
Entry::Occupied(ref mut e) => {
|
||||
match *e.get_mut() {
|
||||
Value::Table(ref mut t) => {
|
||||
insert_key_into(String::from(next.unwrap()), rest_path, value, t);
|
||||
},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
} else {
|
||||
},
|
||||
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);
|
||||
map.insert(current, Value::Table(submap));
|
||||
submap }));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_value(value: String) -> Value {
|
||||
fn parse_value(value: Cow<str>) -> Value {
|
||||
use std::str::FromStr;
|
||||
|
||||
fn is_ary(v: &String) -> bool {
|
||||
v.chars().next() == Some('[') && v.chars().last() == Some(']') && v.len() >= 3
|
||||
fn is_ary(v: &str) -> bool {
|
||||
v.starts_with('[') && v.ends_with(']') && v.len() >= 3
|
||||
}
|
||||
|
||||
if value == "true" {
|
||||
|
@ -79,7 +83,7 @@ fn parse_value(value: String) -> Value {
|
|||
} else if is_ary(&value) {
|
||||
debug!("Building Array out of: {:?}...", value);
|
||||
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 {
|
||||
FromStr::from_str(&value[..])
|
||||
.map(|i: i64| {
|
||||
|
@ -94,7 +98,7 @@ fn parse_value(value: String) -> Value {
|
|||
})
|
||||
.unwrap_or_else(|_| {
|
||||
debug!("Building String out of: {:?}...", value);
|
||||
Value::String(value)
|
||||
Value::String(value.into_owned())
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -77,8 +77,7 @@ fn alter(rt: &Runtime, id: &str, add: Option<&str>, rem: Option<&str>, set: Opti
|
|||
.retrieve(path)
|
||||
.map(|mut e| {
|
||||
add.map(|tags| {
|
||||
let tags = tags.split(",");
|
||||
for tag in tags {
|
||||
for tag in tags.split(',') {
|
||||
info!("Adding tag '{}'", tag);
|
||||
if let Err(e) = e.add_tag(String::from(tag)) {
|
||||
trace_error(&e);
|
||||
|
@ -87,8 +86,7 @@ fn alter(rt: &Runtime, id: &str, add: Option<&str>, rem: Option<&str>, set: Opti
|
|||
});
|
||||
|
||||
rem.map(|tags| {
|
||||
let tags = tags.split(",");
|
||||
for tag in tags {
|
||||
for tag in tags.split(',') {
|
||||
info!("Removing tag '{}'", tag);
|
||||
if let Err(e) = e.remove_tag(String::from(tag)) {
|
||||
trace_error(&e);
|
||||
|
@ -98,7 +96,7 @@ fn alter(rt: &Runtime, id: &str, add: Option<&str>, rem: Option<&str>, set: Opti
|
|||
|
||||
set.map(|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) {
|
||||
trace_error(&e);
|
||||
}
|
||||
|
|
|
@ -15,11 +15,11 @@ pub enum ViewErrorKind {
|
|||
}
|
||||
|
||||
fn view_error_type_as_str(e: &ViewErrorKind) -> &'static str {
|
||||
match e {
|
||||
&ViewErrorKind::StoreError => "Store error",
|
||||
&ViewErrorKind::NoVersion => "No version specified",
|
||||
&ViewErrorKind::PatternError => "Error in Pattern",
|
||||
&ViewErrorKind::GlobBuildError => "Could not build glob() Argument",
|
||||
match *e {
|
||||
ViewErrorKind::StoreError => "Store error",
|
||||
ViewErrorKind::NoVersion => "No version specified",
|
||||
ViewErrorKind::PatternError => "Error in Pattern",
|
||||
ViewErrorKind::GlobBuildError => "Could not build glob() Argument",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ impl ViewError {
|
|||
* Get the error type of this ViewError
|
||||
*/
|
||||
pub fn err_type(&self) -> ViewErrorKind {
|
||||
self.err_type.clone()
|
||||
self.err_type
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ impl ViewError {
|
|||
impl Display for ViewError {
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ impl Display for ViewError {
|
|||
impl Error for ViewError {
|
||||
|
||||
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> {
|
||||
|
|
|
@ -129,7 +129,7 @@ fn load_entry<'a>(id: &str,
|
|||
|
||||
let version = {
|
||||
if version.is_none() {
|
||||
let r = id.split("~").last();
|
||||
let r = id.split('~').last();
|
||||
if r.is_none() {
|
||||
warn!("No version");
|
||||
return Err(ViewError::new(ViewErrorKind::NoVersion, None));
|
||||
|
@ -144,7 +144,7 @@ fn load_entry<'a>(id: &str,
|
|||
debug!("Building path from {:?} and {:?}", id, version);
|
||||
let mut path = rt.store().path().clone();
|
||||
|
||||
if id.chars().next() == Some('/') {
|
||||
if id.starts_with('/') {
|
||||
path.push(format!("{}~{}", &id[1..id.len()], version));
|
||||
} else {
|
||||
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();
|
||||
|
||||
if id.chars().next() == Some('/') {
|
||||
if id.starts_with('/') {
|
||||
path.push(format!("{}~*", &id[1..id.len()]));
|
||||
} else {
|
||||
path.push(format!("{}~*", id));
|
||||
|
|
|
@ -144,12 +144,12 @@ impl<'a> Counter<'a> {
|
|||
}
|
||||
|
||||
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> {
|
||||
|
||||
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);
|
||||
match store.retrieve(id) {
|
||||
Err(e) => Err(CE::new(CEK::StoreReadError, Some(Box::new(e)))),
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use std::error::Error;
|
||||
use std::fmt::Error as FmtError;
|
||||
use std::clone::Clone;
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
/**
|
||||
|
@ -15,11 +14,11 @@ pub enum CounterErrorKind {
|
|||
}
|
||||
|
||||
fn counter_error_type_as_str(e: &CounterErrorKind) -> &'static str {
|
||||
match e {
|
||||
&CounterErrorKind::StoreReadError => "Store read error",
|
||||
&CounterErrorKind::StoreWriteError => "Store write error",
|
||||
&CounterErrorKind::HeaderTypeError => "Header type error",
|
||||
&CounterErrorKind::HeaderFieldMissingError => "Header field missing error",
|
||||
match *e {
|
||||
CounterErrorKind::StoreReadError => "Store read error",
|
||||
CounterErrorKind::StoreWriteError => "Store write error",
|
||||
CounterErrorKind::HeaderTypeError => "Header type error",
|
||||
CounterErrorKind::HeaderFieldMissingError => "Header field missing error",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,7 +58,7 @@ impl CounterError {
|
|||
* Get the error type of this CounterError
|
||||
*/
|
||||
pub fn err_type(&self) -> CounterErrorKind {
|
||||
self.err_type.clone()
|
||||
self.err_type
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -67,7 +66,7 @@ impl CounterError {
|
|||
impl Display for CounterError {
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
|
@ -76,7 +75,7 @@ impl Display for CounterError {
|
|||
impl Error for CounterError {
|
||||
|
||||
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> {
|
||||
|
|
|
@ -14,15 +14,15 @@ struct EqGt {
|
|||
impl Predicate for EqGt {
|
||||
|
||||
fn evaluate(&self, v: Value) -> bool {
|
||||
match &self.comp {
|
||||
&Value::Integer(i) => {
|
||||
match self.comp {
|
||||
Value::Integer(i) => {
|
||||
match v {
|
||||
Value::Integer(j) => i > j,
|
||||
Value::Float(f) => (i as f64) > f,
|
||||
_ => false,
|
||||
}
|
||||
},
|
||||
&Value::Float(f) => {
|
||||
Value::Float(f) => {
|
||||
match v {
|
||||
Value::Integer(i) => f > (i as f64),
|
||||
Value::Float(d) => f > d,
|
||||
|
|
|
@ -27,11 +27,11 @@ impl Filter for FieldIsEmpty {
|
|||
.map(|v| {
|
||||
match v {
|
||||
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::Table(t)) => t.is_empty(),
|
||||
Some(Value::Boolean(_)) |
|
||||
Some(Value::Float(_)) |
|
||||
Some(Value::Integer(_)) => false,
|
||||
_ => true,
|
||||
}
|
||||
})
|
||||
|
|
|
@ -21,11 +21,11 @@ impl Type {
|
|||
|
||||
fn matches(&self, v: &Value) -> bool {
|
||||
match (self, v) {
|
||||
(&Type::String, &Value::String(_)) => true,
|
||||
(&Type::Integer, &Value::Integer(_)) => true,
|
||||
(&Type::Float, &Value::Float(_)) => true,
|
||||
(&Type::Boolean, &Value::Boolean(_)) => true,
|
||||
(&Type::Array, &Value::Array(_)) => true,
|
||||
(&Type::String, &Value::String(_)) |
|
||||
(&Type::Integer, &Value::Integer(_)) |
|
||||
(&Type::Float, &Value::Float(_)) |
|
||||
(&Type::Boolean, &Value::Boolean(_)) |
|
||||
(&Type::Array, &Value::Array(_)) |
|
||||
(&Type::Table, &Value::Table(_)) => true,
|
||||
_ => false,
|
||||
}
|
||||
|
|
|
@ -14,15 +14,15 @@ struct EqLt {
|
|||
impl Predicate for EqLt {
|
||||
|
||||
fn evaluate(&self, v: Value) -> bool {
|
||||
match &self.comp {
|
||||
&Value::Integer(i) => {
|
||||
match self.comp {
|
||||
Value::Integer(i) => {
|
||||
match v {
|
||||
Value::Integer(j) => i < j,
|
||||
Value::Float(f) => (i as f64) < f,
|
||||
_ => false,
|
||||
}
|
||||
},
|
||||
&Value::Float(f) => {
|
||||
Value::Float(f) => {
|
||||
match v {
|
||||
Value::Integer(i) => f < (i as f64),
|
||||
Value::Float(d) => f < d,
|
||||
|
|
|
@ -23,7 +23,7 @@ impl Filter for VersionEq {
|
|||
e.get_header()
|
||||
.read("imag.version")
|
||||
.map(|val| {
|
||||
val.map(|v| {
|
||||
val.map_or(false, |v| {
|
||||
match v {
|
||||
Value::String(s) => {
|
||||
match Version::parse(&s[..]) {
|
||||
|
@ -34,7 +34,6 @@ impl Filter for VersionEq {
|
|||
_ => false,
|
||||
}
|
||||
})
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ impl Filter for VersionGt {
|
|||
e.get_header()
|
||||
.read("imag.version")
|
||||
.map(|val| {
|
||||
val.map(|v| {
|
||||
val.map_or(false, |v| {
|
||||
match v {
|
||||
Value::String(s) => {
|
||||
match Version::parse(&s[..]) {
|
||||
|
@ -34,7 +34,6 @@ impl Filter for VersionGt {
|
|||
_ => false,
|
||||
}
|
||||
})
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ impl Filter for VersionLt {
|
|||
e.get_header()
|
||||
.read("imag.version")
|
||||
.map(|val| {
|
||||
val.map(|v| {
|
||||
val.map_or(false, |v| {
|
||||
match v {
|
||||
Value::String(s) => {
|
||||
match Version::parse(&s[..]) {
|
||||
|
@ -34,7 +34,6 @@ impl Filter for VersionLt {
|
|||
_ => false,
|
||||
}
|
||||
})
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue