diff --git a/src/model/triple.rs b/src/model/triple.rs index 71755b57..458eeddd 100644 --- a/src/model/triple.rs +++ b/src/model/triple.rs @@ -180,27 +180,27 @@ impl fmt::Display for Triple { impl TripleLike for Triple { fn subject(&self) -> &NamedOrBlankNode { - return &self.subject; + &self.subject } fn subject_owned(self) -> NamedOrBlankNode { - return self.subject; + self.subject } fn predicate(&self) -> &NamedNode { - return &self.predicate; + &self.predicate } fn predicate_owned(self) -> NamedNode { - return self.predicate; + self.predicate } fn object(&self) -> &Term { - return &self.object; + &self.object } fn object_owned(self) -> Term { - return self.object; + self.object } } @@ -254,36 +254,36 @@ impl fmt::Display for Quad { impl TripleLike for Quad { fn subject(&self) -> &NamedOrBlankNode { - return &self.subject; + &self.subject } fn subject_owned(self) -> NamedOrBlankNode { - return self.subject; + self.subject } fn predicate(&self) -> &NamedNode { - return &self.predicate; + &self.predicate } fn predicate_owned(self) -> NamedNode { - return self.predicate; + self.predicate } fn object(&self) -> &Term { - return &self.object; + &self.object } fn object_owned(self) -> Term { - return self.object; + self.object } } impl QuadLike for Quad { fn graph_name(&self) -> &Option { - return &self.graph_name; + &self.graph_name } fn graph_name_owned(self) -> Option { - return self.graph_name; + self.graph_name } } diff --git a/src/rio/turtle/mod.rs b/src/rio/turtle/mod.rs index a4bc6325..b5a5abeb 100644 --- a/src/rio/turtle/mod.rs +++ b/src/rio/turtle/mod.rs @@ -20,7 +20,7 @@ mod grammar { } impl ParserState { - fn url_parser<'a>(&'a self) -> ParseOptions<'a> { + fn url_parser(&self) -> ParseOptions { Url::options().base_url(self.base_uri.as_ref()) } } diff --git a/src/rio/turtle/turtle_grammar.rustpeg b/src/rio/turtle/turtle_grammar.rustpeg index 93201d17..44319c53 100644 --- a/src/rio/turtle/turtle_grammar.rustpeg +++ b/src/rio/turtle/turtle_grammar.rustpeg @@ -46,7 +46,7 @@ sparqlBase -> () = "BASE"i _ i:IRIREF {? //[6s] sparqlPrefix -> () = "PREFIX"i _ ns:PNAME_NS _ i:IRIREF { - state.namespaces.insert(ns.into(), i.into()); + state.namespaces.insert(ns.into(), i); } //[6] diff --git a/src/sparql/algebra.rs b/src/sparql/algebra.rs index e6c8d1d5..a46aff3b 100644 --- a/src/sparql/algebra.rs +++ b/src/sparql/algebra.rs @@ -76,7 +76,7 @@ impl<'a> fmt::Display for SparqlPropertyPath<'a> { impl From for PropertyPath { fn from(p: NamedNode) -> Self { - PropertyPath::PredicatePath(p.into()) + PropertyPath::PredicatePath(p) } } @@ -502,8 +502,7 @@ impl<'a> fmt::Display for SparqlExpression<'a> { SparqlExpression(&*b), SparqlExpression(cv) ) - }) - .unwrap_or_else(|| { + }).unwrap_or_else(|| { write!( f, "SUBSTR({}, {})", @@ -523,8 +522,7 @@ impl<'a> fmt::Display for SparqlExpression<'a> { SparqlExpression(&*c), dv ) - }) - .unwrap_or_else(|| { + }).unwrap_or_else(|| { write!( f, "REPLACE({}, {}, {})", @@ -634,8 +632,7 @@ impl<'a> fmt::Display for SparqlExpression<'a> { SparqlExpression(&*b), cv ) - }) - .unwrap_or_else(|| { + }).unwrap_or_else(|| { write!( f, "REGEX({}, {})", @@ -729,7 +726,7 @@ impl From for MultiSetPattern { } impl MultiSetPattern { - pub fn visible_variables<'a>(&'a self) -> BTreeSet<&'a Variable> { + pub fn visible_variables(&self) -> BTreeSet<&Variable> { let mut vars = BTreeSet::default(); self.add_visible_variables(&mut vars); vars @@ -1102,8 +1099,7 @@ impl<'a> fmt::Display for SparqlListPattern<'a> { start, length ) - }) - .unwrap_or_else(|| { + }).unwrap_or_else(|| { write!( f, "{} LIMIT {}", @@ -1118,7 +1114,7 @@ impl<'a> fmt::Display for SparqlListPattern<'a> { } } -fn build_sparql_select_arguments(args: &Vec) -> String { +fn build_sparql_select_arguments(args: &[Variable]) -> String { if args.is_empty() { "*".to_owned() } else { @@ -1263,8 +1259,7 @@ impl<'a> fmt::Display for SparqlAggregation<'a> { SparqlExpression(e), s.escape() ) - }) - .unwrap_or_else(|| write!(f, "GROUP_CONCAT({})", SparqlExpression(e))) + }).unwrap_or_else(|| write!(f, "GROUP_CONCAT({})", SparqlExpression(e))) }, } } diff --git a/src/sparql/parser.rs b/src/sparql/parser.rs index 7c9510f6..fb7b9980 100644 --- a/src/sparql/parser.rs +++ b/src/sparql/parser.rs @@ -228,7 +228,7 @@ mod grammar { } } None => { - pv.extend(p.visible_variables().into_iter().map(|v| v.clone())) //TODO: is it really useful to do a projection? + pv.extend(p.visible_variables().into_iter().cloned()) //TODO: is it really useful to do a projection? } } let mut m = ListPattern::from(p); @@ -266,19 +266,16 @@ mod grammar { } impl ParserState { - fn url_parser<'a>(&'a self) -> ParseOptions<'a> { + fn url_parser(&self) -> ParseOptions { Url::options().base_url(self.base_uri.as_ref()) } fn new_aggregation(&mut self, agg: Aggregation) -> Variable { - self.aggregations - .get(&agg) - .map(|v| v.clone()) - .unwrap_or_else(|| { - let new_var = Variable::default(); - self.aggregations.insert(agg, new_var.clone()); - new_var - }) + self.aggregations.get(&agg).cloned().unwrap_or_else(|| { + let new_var = Variable::default(); + self.aggregations.insert(agg, new_var.clone()); + new_var + }) } } @@ -314,11 +311,11 @@ pub use self::grammar::read_sparql_query; fn needs_unescape_unicode_codepoints(input: &str) -> bool { let bytes = input.as_bytes(); for i in 1..bytes.len() { - if (bytes[i] == ('u' as u8) || bytes[i] == ('U' as u8)) && bytes[i - 1] == ('/' as u8) { + if (bytes[i] == b'u' || bytes[i] == b'U') && bytes[i - 1] == b'/' { return true; } } - return false; + false } struct UnescapeUnicodeCharIterator<'a> { @@ -393,7 +390,7 @@ impl<'a> Iterator for UnescapeUnicodeCharIterator<'a> { } } -fn unescape_unicode_codepoints<'a>(input: Cow<'a, str>) -> Cow<'a, str> { +fn unescape_unicode_codepoints(input: Cow) -> Cow { if needs_unescape_unicode_codepoints(&input) { UnescapeUnicodeCharIterator::new(&input).collect() } else { diff --git a/src/sparql/sparql_grammar.rustpeg b/src/sparql/sparql_grammar.rustpeg index 398819ef..f129d9e1 100644 --- a/src/sparql/sparql_grammar.rustpeg +++ b/src/sparql/sparql_grammar.rustpeg @@ -257,7 +257,9 @@ GroupGraphPatternSub -> MultiSetPattern = a:TriplesBlock? _ b:GroupGraphPatternS } GroupGraphPatternSub_item -> Vec = a:GraphPatternNotTriples _ ('.' _)? b:TriplesBlock? _ { let mut result = vec![a]; - b.map(|v| result.push(PartialGraphPattern::Other(MultiSetPattern::BGP(v)))); + if let Some(v) = b { + result.push(PartialGraphPattern::Other(MultiSetPattern::BGP(v))); + } result } @@ -270,7 +272,7 @@ TriplesBlock -> Vec = h:TriplesSameSubjectPath _ t:TriplesB triples } TriplesBlock_tail -> Vec = '.' _ t:TriplesBlock? _ { - t.unwrap_or_else(|| Vec::default()) + t.unwrap_or_else(Vec::default) } //[56] @@ -308,7 +310,9 @@ DataBlock -> MultiSetPattern = l:(InlineDataOneVar / InlineDataFull) { InlineDataOneVar -> Vec = var:Var _ '{' _ d:InlineDataOneVar_value* '}' { d.into_iter().map(|val| { let mut bindings = Binding::default(); - val.map(|v| bindings.insert(var.clone(), v)); + if let Some(v) = val { + bindings.insert(var.clone(), v); + } bindings }).collect() } @@ -319,7 +323,9 @@ InlineDataFull -> Vec = '(' _ vars:InlineDataFull_var* _ ')' _ '{' _ va val.into_iter().map(|vals| { let mut bindings = Binding::default(); for (var, val) in vars.iter().zip(vals.into_iter()) { - val.map(|v| bindings.insert(var.clone(), v)); + if let Some(v) = val { + bindings.insert(var.clone(), v); + } } bindings }).collect() @@ -359,7 +365,7 @@ Constraint -> Expression = BrackettedExpression / BuiltInCall / FunctionCall //[70] FunctionCall -> Expression = f: iri _ a: ArgList { - Expression::CustomFunctionCall(f, a.into()) + Expression::CustomFunctionCall(f, a) } //[71] @@ -392,7 +398,7 @@ TriplesSameSubject -> Vec = patterns.push(TriplePattern::new(s.clone(), p.clone(), o)) } } - patterns.into_iter().map(|p| p.into()).collect() + patterns } / s:TriplesNode _ po:PropertyList { let mut patterns = s.patterns; @@ -402,7 +408,7 @@ TriplesSameSubject -> Vec = patterns.push(TriplePattern::new(s.focus.clone(), p.clone(), o)) } } - patterns.into_iter().map(|p| p.into()).collect() + patterns } //[76] @@ -420,7 +426,7 @@ PropertyListNotEmpty -> FocusedTriplePattern FocusedTriplePattern<(NamedNodeOrVariable,Vec)> = p:Verb _ o:ObjectList _ { FocusedTriplePattern { - focus: (p.into(), o.focus), + focus: (p, o.focus), patterns: o.patterns } } @@ -558,9 +564,9 @@ PathNegatedPropertySet -> PropertyPath = Either::Right(b) => inverse.push(b) } } - if inverse.len() == 0 { + if inverse.is_empty() { PropertyPath::NegatedPropertySet(direct) - } else if direct.len() == 0 { + } else if direct.is_empty() { PropertyPath::InversePath(Box::new(PropertyPath::NegatedPropertySet(inverse))) } else { PropertyPath::AlternativePath( @@ -903,7 +909,7 @@ iri -> NamedNode = i:(IRIREF / PrefixedName) {? //[137] PrefixedName -> String = PNAME_LN / - ns:PNAME_NS {? state.namespaces.get(ns).map(|v| v.clone()).ok_or("Prefix not found") } + ns:PNAME_NS {? state.namespaces.get(ns).cloned().ok_or("Prefix not found") } //[138] BlankNode -> BlankNode = diff --git a/src/store/isomorphism.rs b/src/store/isomorphism.rs index c84155cc..4da28db9 100644 --- a/src/store/isomorphism.rs +++ b/src/store/isomorphism.rs @@ -57,7 +57,7 @@ fn hash_blank_nodes( let mut bnodes_by_hash: HashMap> = HashMap::default(); // NB: we need to sort the triples to have the same hash - for bnode in bnodes.into_iter() { + for bnode in bnodes { let mut hasher = DefaultHasher::new(); { diff --git a/src/store/memory.rs b/src/store/memory.rs index d6e7e156..ac9170ee 100644 --- a/src/store/memory.rs +++ b/src/store/memory.rs @@ -64,7 +64,7 @@ impl EncodedQuadsStore for MemoryStore { fn quads(&self) -> Result<> as IntoIterator>::IntoIter> { let mut result = Vec::default(); for (graph_name, graph) in self.graph_indexes.read()?.iter() { - for (s, pos) in graph.spo.iter() { + for (s, pos) in &graph.spo { for (p, os) in pos.iter() { for o in os.iter() { result.push(Ok(encoded_quad(s, p, o, graph_name))) @@ -205,7 +205,7 @@ impl EncodedQuadsStore for MemoryStore { ) -> Result<> as IntoIterator>::IntoIter> { let mut result = Vec::default(); if let Some(graph) = self.graph_indexes.read()?.get(graph_name) { - for (s, pos) in graph.spo.iter() { + for (s, pos) in &graph.spo { for (p, os) in pos.iter() { for o in os.iter() { result.push(Ok(encoded_quad(s, p, o, graph_name))) @@ -340,10 +340,8 @@ impl EncodedQuadsStore for MemoryStore { po.get(&quad.predicate) .map(|o| o.contains(&quad.object)) .unwrap_or(false) - }) - .unwrap_or(false) - }) - .unwrap_or(false)) + }).unwrap_or(false) + }).unwrap_or(false)) } fn insert(&self, quad: &EncodedQuad) -> Result<()> { diff --git a/src/store/numeric_encoder.rs b/src/store/numeric_encoder.rs index e8433512..2d2ffe50 100644 --- a/src/store/numeric_encoder.rs +++ b/src/store/numeric_encoder.rs @@ -213,7 +213,7 @@ impl Encoder { } pub fn encode_blank_node(&self, blank_node: &BlankNode) -> Result { - Ok(EncodedTerm::BlankNode(blank_node.deref().clone())) + Ok(EncodedTerm::BlankNode(*blank_node.deref())) } pub fn encode_literal(&self, literal: &Literal) -> Result { @@ -347,7 +347,7 @@ impl Encoder { fn decode_value(&self, id: u64) -> Result { self.string_store .get_bytes(id)? - .ok_or("value not found in the dictionary".into()) + .ok_or_else(|| "value not found in the dictionary".into()) } } diff --git a/src/store/rocksdb.rs b/src/store/rocksdb.rs index c23a73f3..d1d5cca4 100644 --- a/src/store/rocksdb.rs +++ b/src/store/rocksdb.rs @@ -23,17 +23,17 @@ impl RocksDbDataset { } } -const ID2STR_CF: &'static str = "id2str"; -const STR2ID_CF: &'static str = "id2str"; -const SPOG_CF: &'static str = "spog"; -const POSG_CF: &'static str = "posg"; -const OSPG_CF: &'static str = "ospg"; +const ID2STR_CF: &str = "id2str"; +const STR2ID_CF: &str = "id2str"; +const SPOG_CF: &str = "spog"; +const POSG_CF: &str = "posg"; +const OSPG_CF: &str = "ospg"; const EMPTY_BUF: [u8; 0] = [0 as u8; 0]; //TODO: indexes for the default graph and indexes for the named graphs (no more Optional and space saving) -const COLUMN_FAMILIES: [&'static str; 5] = [ID2STR_CF, STR2ID_CF, SPOG_CF, POSG_CF, OSPG_CF]; +const COLUMN_FAMILIES: [&str; 5] = [ID2STR_CF, STR2ID_CF, SPOG_CF, POSG_CF, OSPG_CF]; pub struct RocksDbStore { db: DB, @@ -322,7 +322,8 @@ impl EncodedQuadsStore for RocksDbStore { batch.put_cf(self.spog_cf, &encode_spog_quad(quad)?, &EMPTY_BUF)?; batch.put_cf(self.posg_cf, &encode_posg_quad(quad)?, &EMPTY_BUF)?; batch.put_cf(self.ospg_cf, &encode_ospg_quad(quad)?, &EMPTY_BUF)?; - Ok(self.db.write(batch)?) //TODO: check what's going on if the key already exists + self.db.write(batch)?; //TODO: check what's going on if the key already exists + Ok(()) } fn remove(&self, quad: &EncodedQuad) -> Result<()> { @@ -330,7 +331,8 @@ impl EncodedQuadsStore for RocksDbStore { batch.delete_cf(self.spog_cf, &encode_spog_quad(quad)?)?; batch.delete_cf(self.posg_cf, &encode_posg_quad(quad)?)?; batch.delete_cf(self.ospg_cf, &encode_ospg_quad(quad)?)?; - Ok(self.db.write(batch)?) + self.db.write(batch)?; + Ok(()) } } diff --git a/src/store/store.rs b/src/store/store.rs index 831a55bd..c40a7cf8 100644 --- a/src/store/store.rs +++ b/src/store/store.rs @@ -276,7 +276,7 @@ impl Dataset for StoreDataset { impl fmt::Display for StoreDataset { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { for quad in self.iter()? { - write!(fmt, "{}\n", quad?)?; + writeln!(fmt, "{}", quad?)?; } Ok(()) } @@ -465,7 +465,7 @@ impl NamedGraph for StoreNamedGraph { impl fmt::Display for StoreNamedGraph { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { for triple in self.iter()? { - write!(fmt, "{}\n", triple?)?; + writeln!(fmt, "{}", triple?)?; } Ok(()) } @@ -620,7 +620,7 @@ impl Graph for StoreDefaultGraph { impl fmt::Display for StoreDefaultGraph { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { for triple in self.iter()? { - write!(fmt, "{}\n", triple?)?; + writeln!(fmt, "{}", triple?)?; } Ok(()) } @@ -761,8 +761,7 @@ impl Graph for StoreUnionGraph { &encoder.encode_named_or_blank_node(triple.subject())?, &encoder.encode_named_node(triple.predicate())?, &encoder.encode_term(triple.object())?, - )? - .any(|_| true)) + )?.any(|_| true)) } fn insert(&self, triple: &Triple) -> Result<()> { @@ -785,7 +784,7 @@ impl Graph for StoreUnionGraph { impl fmt::Display for StoreUnionGraph { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { for triple in self.iter()? { - write!(fmt, "{}\n", triple?)?; + writeln!(fmt, "{}", triple?)?; } Ok(()) } diff --git a/src/utils.rs b/src/utils.rs index 5f1a00fb..85de85b0 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -4,13 +4,13 @@ pub trait Escaper { impl<'a> Escaper for &'a str { fn escape(&self) -> String { - self.chars().flat_map(|c| EscapeRDF::new(c)).collect() + self.chars().flat_map(EscapeRDF::new).collect() } } impl Escaper for String { fn escape(&self) -> String { - self.chars().flat_map(|c| EscapeRDF::new(c)).collect() + self.chars().flat_map(EscapeRDF::new).collect() } } diff --git a/tests/rdf_test_cases.rs b/tests/rdf_test_cases.rs index 80a2db7b..bc402bf0 100644 --- a/tests/rdf_test_cases.rs +++ b/tests/rdf_test_cases.rs @@ -95,11 +95,10 @@ fn turtle_w3c_testsuite() { .map(|r| client.load_turtle(r)) .unwrap_or_else(|| Ok(MemoryGraph::default())); assert!( - action_graph.is_err() - || !action_graph - .unwrap() - .is_isomorphic(&result_graph.unwrap()) - .unwrap(), + action_graph.is_err() || !action_graph + .unwrap() + .is_isomorphic(&result_graph.unwrap()) + .unwrap(), "Failure on {}", test ); @@ -252,21 +251,21 @@ pub mod mf { use std::str::FromStr; lazy_static! { - pub static ref INCLUDE: NamedNode = NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#include" - ).unwrap(); - pub static ref ENTRIES: NamedNode = NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#entries" - ).unwrap(); - pub static ref NAME: NamedNode = NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#name" - ).unwrap(); - pub static ref ACTION: NamedNode = NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#action" - ).unwrap(); - pub static ref RESULT: NamedNode = NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#result" - ).unwrap(); + pub static ref INCLUDE: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#include") + .unwrap(); + pub static ref ENTRIES: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#entries") + .unwrap(); + pub static ref NAME: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#name") + .unwrap(); + pub static ref ACTION: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#action") + .unwrap(); + pub static ref RESULT: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#result") + .unwrap(); } }