diff --git a/Cranky.toml b/Cranky.toml new file mode 100644 index 00000000..f9c91acd --- /dev/null +++ b/Cranky.toml @@ -0,0 +1,39 @@ +allow = [] + +deny = [ + "clippy::complexity", + "clippy::expect_used", + "clippy::implicit_clone", + "clippy::manual_string_new", + "clippy::map_unwrap_or", + "clippy::match_same_arms", + "clippy::option_as_ref_deref", + "clippy::option_filter_map", + "clippy::option_map_unit_fn", + "clippy::or_then_unwrap", + "clippy::panic", + "clippy::range_plus_one", + "clippy::redundant_clone", + "clippy::redundant_closure_for_method_calls", + "clippy::semicolon_if_nothing_returned", + "clippy::single_match_else", + "clippy::unnecessary_cast", + "clippy::unnecessary_wraps", + "clippy::unused_self", + "clippy::unwrap_used", + "clippy::useless_asref", + "clippy::useless_conversion", + "clippy::useless_format", + "nonstandard-style", + "rust_2018_idioms", + "rust-2021-compatibility", + "trivial_casts", + "trivial_numeric_casts", + "unsafe_code", + "unused_import_braces", + "unused_lifetimes", + "unused_qualifications", + "warnings", +] + +warn = [] diff --git a/Makefile.toml b/Makefile.toml index acc967ed..ab510824 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -11,17 +11,7 @@ dependencies = ["install-rustfmt"] description = "Check format of sources files." [tasks.lint-rust] -args = [ - "clippy", - "--workspace", - "--locked", - "--all-targets", - "--", - "-D", - "clippy::all", - "-D", - "warnings", -] +args = ["cranky"] command = "cargo" dependencies = ["install-clippy"] description = "Check lint of all sources files." @@ -513,6 +503,10 @@ install_crate = { rustup_component_name = "llvm-tools-preview" } [tasks.install-clippy] install_crate = { rustup_component_name = "clippy" } +[tasks.intall-cranky] +dependencies = ["install-clippy"] +install_crate = { crate_name = "cranky" } + [tasks.install-rustfmt] install_crate = { rustup_component_name = "rustfmt" } diff --git a/contracts/okp4-cognitarium/src/contract.rs b/contracts/okp4-cognitarium/src/contract.rs index 8d7f0b07..95a38a84 100644 --- a/contracts/okp4-cognitarium/src/contract.rs +++ b/contracts/okp4-cognitarium/src/contract.rs @@ -16,7 +16,7 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( - deps: DepsMut, + deps: DepsMut<'_>, _env: Env, info: MessageInfo, msg: InstantiateMsg, @@ -31,7 +31,7 @@ pub fn instantiate( #[cfg_attr(not(feature = "library"), entry_point)] pub fn execute( - deps: DepsMut, + deps: DepsMut<'_>, _env: Env, info: MessageInfo, msg: ExecuteMsg, @@ -52,13 +52,13 @@ pub mod execute { use std::io::BufReader; pub fn insert( - deps: DepsMut, + deps: DepsMut<'_>, info: MessageInfo, format: DataFormat, data: Binary, ) -> Result { if STORE.load(deps.storage)?.owner != info.sender { - Err(ContractError::Unauthorized)? + Err(ContractError::Unauthorized)?; } let buf = BufReader::new(data.as_slice()); @@ -73,7 +73,7 @@ pub mod execute { } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { +pub fn query(deps: Deps<'_>, _env: Env, msg: QueryMsg) -> StdResult { match msg { QueryMsg::Store => to_binary(&query::store(deps)?), QueryMsg::Select { query } => to_binary(&query::select(deps, query)?), @@ -97,22 +97,22 @@ pub mod query { use crate::querier::{PlanBuilder, QueryEngine}; use crate::rdf::{self, Atom, TripleWriter}; - pub fn store(deps: Deps) -> StdResult { - STORE.load(deps.storage).map(|s| s.into()) + pub fn store(deps: Deps<'_>) -> StdResult { + STORE.load(deps.storage).map(Into::into) } - pub fn select(deps: Deps, query: SelectQuery) -> StdResult { + pub fn select(deps: Deps<'_>, query: SelectQuery) -> StdResult { let store = STORE.load(deps.storage)?; if query.select.len() > store.limits.max_query_variable_count as usize { Err(StdError::generic_err( "Maximum query variable count exceeded", - ))? + ))?; } let count = query.limit.unwrap_or(store.limits.max_query_limit); if count > store.limits.max_query_limit { - Err(StdError::generic_err("Maximum query limit exceeded"))? + Err(StdError::generic_err("Maximum query limit exceeded"))?; } let plan = PlanBuilder::new(deps.storage, &query.prefixes) @@ -123,7 +123,7 @@ pub mod query { } pub fn describe( - deps: Deps, + deps: Deps<'_>, query: DescribeQuery, format: DataFormat, ) -> StdResult { @@ -134,7 +134,7 @@ pub mod query { ) -> Result { vars.get(index) .and_then(|it| bindings.get(it.as_str())) - .map(|it| it.to_owned()) + .cloned() .ok_or_else(|| { StdError::generic_err(format!( "Variable index {index} not found (this was unexpected)" @@ -192,12 +192,7 @@ pub mod query { if let VarOrNamedNode::NamedNode(iri) = &query.resource { vars.insert(0, s.clone()); for b in &mut bindings { - b.insert( - s.clone(), - Value::URI { - value: iri.to_owned(), - }, - ); + b.insert(s.clone(), Value::URI { value: iri.clone() }); } } diff --git a/contracts/okp4-cognitarium/src/querier/engine.rs b/contracts/okp4-cognitarium/src/querier/engine.rs index 8b0c3220..8cb5cf44 100644 --- a/contracts/okp4-cognitarium/src/querier/engine.rs +++ b/contracts/okp4-cognitarium/src/querier/engine.rs @@ -47,7 +47,7 @@ impl<'a> QueryEngine<'a> { }) } - pub fn eval_plan(&'a self, plan: QueryPlan) -> ResolvedVariablesIterator { + pub fn eval_plan(&'a self, plan: QueryPlan) -> ResolvedVariablesIterator<'_> { return self.eval_node(plan.entrypoint)(ResolvedVariables::with_capacity( plan.variables.len(), )); diff --git a/contracts/okp4-cognitarium/src/querier/plan.rs b/contracts/okp4-cognitarium/src/querier/plan.rs index e808b42d..decdf269 100644 --- a/contracts/okp4-cognitarium/src/querier/plan.rs +++ b/contracts/okp4-cognitarium/src/querier/plan.rs @@ -77,16 +77,14 @@ impl QueryNode { predicate.lookup_bound_variable(callback); object.lookup_bound_variable(callback); } - QueryNode::CartesianProductJoin { left, right } => { + QueryNode::CartesianProductJoin { left, right } + | QueryNode::ForLoopJoin { left, right } => { left.lookup_bound_variables(callback); right.lookup_bound_variables(callback); } - QueryNode::ForLoopJoin { left, right } => { - left.lookup_bound_variables(callback); - right.lookup_bound_variables(callback); + QueryNode::Skip { child, .. } | QueryNode::Limit { child, .. } => { + child.lookup_bound_variables(callback); } - QueryNode::Skip { child, .. } => child.lookup_bound_variables(callback), - QueryNode::Limit { child, .. } => child.lookup_bound_variables(callback), } } } diff --git a/contracts/okp4-cognitarium/src/querier/plan_builder.rs b/contracts/okp4-cognitarium/src/querier/plan_builder.rs index 6a3ab9f8..aab92221 100644 --- a/contracts/okp4-cognitarium/src/querier/plan_builder.rs +++ b/contracts/okp4-cognitarium/src/querier/plan_builder.rs @@ -47,7 +47,7 @@ impl<'a> PlanBuilder<'a> { }) .collect::>>()?; - self.build_from_bgp(bgp) + Self::build_from_bgp(bgp) .map(|mut node| { if let Some(skip) = self.skip { node = QueryNode::Skip { @@ -72,7 +72,7 @@ impl<'a> PlanBuilder<'a> { }) } - fn build_from_bgp(&self, bgp: Vec) -> StdResult { + fn build_from_bgp(bgp: Vec) -> StdResult { bgp.into_iter() .reduce(|left: QueryNode, right: QueryNode| -> QueryNode { if left @@ -91,8 +91,10 @@ impl<'a> PlanBuilder<'a> { right: Box::new(right), } }) - .map(Ok) - .unwrap_or_else(|| Err(StdError::generic_err("Empty basic graph pattern"))) + .map_or_else( + || Err(StdError::generic_err("Empty basic graph pattern")), + Ok, + ) } fn build_triple_pattern(&mut self, pattern: &TriplePattern) -> StdResult { @@ -156,24 +158,28 @@ impl<'a> PlanBuilder<'a> { match value { IRI::Prefixed(prefixed) => prefixed .rfind(':') - .map(Ok) - .unwrap_or_else(|| { - Err(StdError::generic_err( - "Malformed prefixed IRI: no prefix delimiter found", - )) - }) + .map_or_else( + || { + Err(StdError::generic_err( + "Malformed prefixed IRI: no prefix delimiter found", + )) + }, + Ok, + ) .and_then(|index| { self.prefixes .get(&prefixed.as_str()[..index]) .map(|resolved_prefix| { [resolved_prefix, &prefixed.as_str()[index + 1..]].join("") }) - .map(Ok) - .unwrap_or_else(|| { - Err(StdError::generic_err( - "Malformed prefixed IRI: prefix not found", - )) - }) + .map_or_else( + || { + Err(StdError::generic_err( + "Malformed prefixed IRI: prefix not found", + )) + }, + Ok, + ) }), IRI::Full(full) => Ok(full), } @@ -307,6 +313,12 @@ mod test { value: "resource".to_string(), }), ), + ( + IRI::Prefixed("resource".to_string()), + Err(StdError::generic_err( + "Malformed prefixed IRI: no prefix delimiter found", + )), + ), ( IRI::Prefixed("okp5:resource".to_string()), Err(StdError::generic_err( diff --git a/contracts/okp4-cognitarium/src/querier/variable.rs b/contracts/okp4-cognitarium/src/querier/variable.rs index 44578bc8..163f4e4b 100644 --- a/contracts/okp4-cognitarium/src/querier/variable.rs +++ b/contracts/okp4-cognitarium/src/querier/variable.rs @@ -31,12 +31,12 @@ impl ResolvedVariable { ResolvedVariable::Predicate(p) => p.clone(), ResolvedVariable::Object(o) => match o { Object::Named(node) => node.clone(), - Object::Blank(_) => None?, - Object::Literal(_) => None?, + Object::Blank(_) | Object::Literal(_) => None?, }, }) } + #[allow(clippy::unnecessary_wraps)] pub fn as_object(&self) -> Option { Some(match self { ResolvedVariable::Subject(s) => match s { @@ -132,7 +132,7 @@ impl ResolvedVariables { } pub fn set(&mut self, index: usize, var: ResolvedVariable) { - self.variables[index] = Some(var) + self.variables[index] = Some(var); } pub fn get(&self, index: usize) -> &Option { diff --git a/contracts/okp4-cognitarium/src/rdf/atom.rs b/contracts/okp4-cognitarium/src/rdf/atom.rs index 9322193a..ee381b9d 100644 --- a/contracts/okp4-cognitarium/src/rdf/atom.rs +++ b/contracts/okp4-cognitarium/src/rdf/atom.rs @@ -15,8 +15,7 @@ pub enum Subject { impl fmt::Display for Subject { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Subject::NamedNode(s) => write!(f, "{s}"), - Subject::BlankNode(s) => write!(f, "{s}"), + Subject::NamedNode(s) | Subject::BlankNode(s) => write!(f, "{s}"), } } } @@ -42,9 +41,7 @@ pub enum Value { impl fmt::Display for Value { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Value::NamedNode(s) => write!(f, "{s}"), - Value::BlankNode(s) => write!(f, "{s}"), - Value::LiteralSimple(s) => write!(f, "{s}"), + Value::NamedNode(s) | Value::BlankNode(s) | Value::LiteralSimple(s) => write!(f, "{s}"), Value::LiteralLang(s, l) => write!(f, "{s}@{l}"), Value::LiteralDatatype(s, d) => write!(f, "{s}^^{d}"), } @@ -59,7 +56,7 @@ pub struct Atom { } impl std::fmt::Display for Atom { - fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fmt.write_str(&format!( "<{}> <{}> '{}'", self.subject, self.property, self.value @@ -72,16 +69,14 @@ impl<'a> From<&'a Atom> for Triple<'a> { fn from(atom: &'a Atom) -> Self { Triple { subject: match &atom.subject { - Subject::NamedNode(s) => NamedNode { iri: s.as_str() }, - Subject::BlankNode(s) => NamedNode { iri: s.as_str() }, + Subject::NamedNode(s) | Subject::BlankNode(s) => NamedNode { iri: s.as_str() }, } .into(), predicate: NamedNode { iri: atom.property.0.as_str(), }, object: match &atom.value { - Value::NamedNode(s) => NamedNode { iri: s.as_str() }.into(), - Value::BlankNode(s) => NamedNode { iri: s.as_str() }.into(), + Value::NamedNode(s) | Value::BlankNode(s) => NamedNode { iri: s.as_str() }.into(), Value::LiteralSimple(s) => Literal::Simple { value: s.as_str() }.into(), Value::LiteralLang(s, l) => Literal::LanguageTaggedString { value: s.as_str(), diff --git a/contracts/okp4-cognitarium/src/rdf/serde.rs b/contracts/okp4-cognitarium/src/rdf/serde.rs index 0366b8e1..ad3e5b5b 100644 --- a/contracts/okp4-cognitarium/src/rdf/serde.rs +++ b/contracts/okp4-cognitarium/src/rdf/serde.rs @@ -46,7 +46,7 @@ impl TripleReader { pub fn read_all(&mut self, mut use_fn: UF) -> Result<(), E> where - UF: FnMut(Triple) -> Result<(), E>, + UF: FnMut(Triple<'_>) -> Result<(), E>, E: From + From, { match &mut self.parser { @@ -54,7 +54,7 @@ impl TripleReader { TriplesParserKind::Turtle(parser) => parser.parse_all(&mut use_fn), TriplesParserKind::RdfXml(parser) => parser.parse_all(&mut use_fn), TriplesParserKind::NQuads(parser) => { - parser.parse_all(&mut |quad: Quad| -> Result<(), E> { + parser.parse_all(&mut |quad: Quad<'_>| -> Result<(), E> { use_fn(Triple { subject: quad.subject, predicate: quad.predicate, diff --git a/contracts/okp4-cognitarium/src/rdf/uri.rs b/contracts/okp4-cognitarium/src/rdf/uri.rs index 6ff96743..b24fb9bc 100644 --- a/contracts/okp4-cognitarium/src/rdf/uri.rs +++ b/contracts/okp4-cognitarium/src/rdf/uri.rs @@ -14,7 +14,7 @@ pub fn explode_iri(iri: &str) -> StdResult<(String, String)> { } if let Some(index) = marker_index { - return Ok((iri[..index + 1].to_string(), iri[index + 1..].to_string())); + return Ok((iri[..=index].to_string(), iri[index + 1..].to_string())); } Err(StdError::generic_err("Couldn't extract IRI namespace")) diff --git a/contracts/okp4-cognitarium/src/state/namespaces.rs b/contracts/okp4-cognitarium/src/state/namespaces.rs index 8e17c424..e224b3c6 100644 --- a/contracts/okp4-cognitarium/src/state/namespaces.rs +++ b/contracts/okp4-cognitarium/src/state/namespaces.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; /// Store a key increment used a unique key for referencing a namespace. Given the size of an `u128` /// there is no need to implement a garbage collector mechanism in case some namespaces are removed. -pub const NAMESPACE_KEY_INCREMENT: Item = Item::new("namespace_key"); +pub const NAMESPACE_KEY_INCREMENT: Item<'_, u128> = Item::new("namespace_key"); #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub struct Namespace { @@ -23,7 +23,8 @@ pub struct NamespaceIndexes<'a> { impl IndexList for NamespaceIndexes<'_> { fn get_indexes(&self) -> Box> + '_> { - Box::new(vec![&self.key as &dyn Index].into_iter()) + let key: &dyn Index = &self.key; + Box::new(vec![key].into_iter()) } } diff --git a/contracts/okp4-cognitarium/src/state/store.rs b/contracts/okp4-cognitarium/src/state/store.rs index 16c0164b..236cf0f0 100644 --- a/contracts/okp4-cognitarium/src/state/store.rs +++ b/contracts/okp4-cognitarium/src/state/store.rs @@ -4,7 +4,7 @@ use cosmwasm_std::{Addr, Uint128}; use cw_storage_plus::Item; use serde::{Deserialize, Serialize}; -pub const STORE: Item = Item::new("store"); +pub const STORE: Item<'_, Store> = Item::new("store"); #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub struct Store { diff --git a/contracts/okp4-cognitarium/src/state/triples.rs b/contracts/okp4-cognitarium/src/state/triples.rs index 87014d1f..95d36240 100644 --- a/contracts/okp4-cognitarium/src/state/triples.rs +++ b/contracts/okp4-cognitarium/src/state/triples.rs @@ -15,7 +15,8 @@ pub struct TripleIndexes<'a> { impl IndexList for TripleIndexes<'_> { fn get_indexes(&self) -> Box> + '_> { - Box::new(vec![&self.subject_and_predicate as &dyn Index].into_iter()) + let subject_and_predicate: &dyn Index = &self.subject_and_predicate; + Box::new(vec![subject_and_predicate].into_iter()) } } @@ -133,7 +134,7 @@ impl Node { where F: FnMut(u128) -> StdResult, { - ns_fn(self.namespace).map(|ns| vec![ns.as_str(), self.value.as_str()].join("")) + ns_fn(self.namespace).map(|ns| [ns.as_str(), self.value.as_str()].join("")) } } diff --git a/contracts/okp4-cognitarium/src/storer.rs b/contracts/okp4-cognitarium/src/storer.rs index e8ad3dd3..234b39e8 100644 --- a/contracts/okp4-cognitarium/src/storer.rs +++ b/contracts/okp4-cognitarium/src/storer.rs @@ -43,17 +43,17 @@ impl<'a> TripleStorer<'a> { self.finish() } - pub fn store_triple(&mut self, t: model::Triple) -> Result<(), ContractError> { + pub fn store_triple(&mut self, t: model::Triple<'_>) -> Result<(), ContractError> { self.store.stat.triple_count += Uint128::one(); if self.store.stat.triple_count > self.store.limits.max_triple_count { - Err(StoreError::TripleCount(self.store.limits.max_triple_count))? + Err(StoreError::TripleCount(self.store.limits.max_triple_count))?; } if self.store.stat.triple_count - self.initial_triple_count > self.store.limits.max_insert_data_triple_count { Err(StoreError::InsertDataTripleCount( self.store.limits.max_insert_data_triple_count, - ))? + ))?; } let t_size = Uint128::from(Self::triple_size(t) as u128); @@ -61,19 +61,19 @@ impl<'a> TripleStorer<'a> { Err(StoreError::TripleByteSize( t_size, self.store.limits.max_triple_byte_size, - ))? + ))?; } self.store.stat.byte_size += t_size; if self.store.stat.byte_size > self.store.limits.max_byte_size { - Err(StoreError::ByteSize(self.store.limits.max_byte_size))? + Err(StoreError::ByteSize(self.store.limits.max_byte_size))?; } if self.store.stat.byte_size - self.initial_byte_size > self.store.limits.max_insert_data_byte_size { Err(StoreError::InsertDataByteSize( self.store.limits.max_insert_data_byte_size, - ))? + ))?; } let triple = self.rio_to_triple(t)?; @@ -102,22 +102,19 @@ impl<'a> TripleStorer<'a> { } fn resolve_namespace_key(&mut self, ns_str: String) -> StdResult { - match self.ns_cache.get_mut(ns_str.as_str()) { - Some(namespace) => { - namespace.counter += 1; - Ok(namespace.key) - } - None => { - let mut namespace = match namespaces().load(self.storage, ns_str.clone()) { - Err(StdError::NotFound { .. }) => Ok(self.allocate_namespace(ns_str.clone())), - Ok(n) => Ok(n), - Err(e) => Err(e), - }?; - - namespace.counter += 1; - self.ns_cache.insert(ns_str, namespace.clone()); - Ok(namespace.key) - } + if let Some(namespace) = self.ns_cache.get_mut(ns_str.as_str()) { + namespace.counter += 1; + Ok(namespace.key) + } else { + let mut namespace = match namespaces().load(self.storage, ns_str.clone()) { + Err(StdError::NotFound { .. }) => Ok(self.allocate_namespace(ns_str.clone())), + Ok(n) => Ok(n), + Err(e) => Err(e), + }?; + + namespace.counter += 1; + self.ns_cache.insert(ns_str, namespace.clone()); + Ok(namespace.key) } } @@ -134,7 +131,7 @@ impl<'a> TripleStorer<'a> { ns } - fn rio_to_triple(&mut self, triple: model::Triple) -> StdResult { + fn rio_to_triple(&mut self, triple: model::Triple<'_>) -> StdResult { Ok(Triple { subject: self.rio_to_subject(triple.subject)?, predicate: self.rio_to_node(triple.predicate)?, @@ -142,7 +139,7 @@ impl<'a> TripleStorer<'a> { }) } - fn rio_to_subject(&mut self, subject: model::Subject) -> StdResult { + fn rio_to_subject(&mut self, subject: model::Subject<'_>) -> StdResult { match subject { model::Subject::NamedNode(node) => self.rio_to_node(node).map(Subject::Named), model::Subject::BlankNode(node) => Ok(Subject::Blank(node.id.to_string())), @@ -150,7 +147,7 @@ impl<'a> TripleStorer<'a> { } } - fn rio_to_node(&mut self, node: model::NamedNode) -> StdResult { + fn rio_to_node(&mut self, node: model::NamedNode<'_>) -> StdResult { let (ns, v) = rdf::explode_iri(node.iri)?; Ok(Node { namespace: self.resolve_namespace_key(ns)?, @@ -158,7 +155,7 @@ impl<'a> TripleStorer<'a> { }) } - fn rio_to_object(&mut self, object: Term) -> StdResult { + fn rio_to_object(&mut self, object: Term<'_>) -> StdResult { match object { Term::BlankNode(node) => Ok(Object::Blank(node.id.to_string())), Term::NamedNode(node) => self.rio_to_node(node).map(Object::Named), @@ -167,7 +164,7 @@ impl<'a> TripleStorer<'a> { } } - fn rio_to_literal(&mut self, literal: model::Literal) -> StdResult { + fn rio_to_literal(&mut self, literal: model::Literal<'_>) -> StdResult { match literal { model::Literal::Simple { value } => Ok(Literal::Simple { value: value.to_string(), @@ -185,13 +182,13 @@ impl<'a> TripleStorer<'a> { } } - fn triple_size(triple: model::Triple) -> usize { + fn triple_size(triple: model::Triple<'_>) -> usize { Self::subject_size(triple.subject) + Self::node_size(triple.predicate) + Self::object_size(triple.object) } - fn subject_size(subject: model::Subject) -> usize { + fn subject_size(subject: model::Subject<'_>) -> usize { match subject { model::Subject::NamedNode(n) => Self::node_size(n), model::Subject::BlankNode(n) => n.id.len(), @@ -199,11 +196,11 @@ impl<'a> TripleStorer<'a> { } } - fn node_size(node: model::NamedNode) -> usize { + fn node_size(node: model::NamedNode<'_>) -> usize { node.iri.len() } - fn object_size(term: Term) -> usize { + fn object_size(term: Term<'_>) -> usize { match term { Term::NamedNode(n) => Self::node_size(n), Term::BlankNode(n) => n.id.len(), diff --git a/contracts/okp4-law-stone/src/contract.rs b/contracts/okp4-law-stone/src/contract.rs index 5fe45ff9..a6af8464 100644 --- a/contracts/okp4-law-stone/src/contract.rs +++ b/contracts/okp4-law-stone/src/contract.rs @@ -153,7 +153,7 @@ pub mod query { let program_uri = object_ref_to_uri(program)?.to_string(); Ok(LogicCustomQuery::Ask { - program: "".to_string(), + program: String::new(), query: ["consult('", program_uri.as_str(), "'), ", query.as_str()].join(""), }) } diff --git a/contracts/okp4-objectarium/src/compress.rs b/contracts/okp4-objectarium/src/compress.rs index ddc6563d..1aeca8ba 100644 --- a/contracts/okp4-objectarium/src/compress.rs +++ b/contracts/okp4-objectarium/src/compress.rs @@ -62,6 +62,7 @@ impl From for CompressionError { /// pass_through returns the data as is. #[inline] +#[allow(clippy::unnecessary_wraps)] fn passthrough(data: &[u8]) -> Result, CompressionError> { Ok(data.to_vec()) } diff --git a/contracts/okp4-objectarium/src/contract.rs b/contracts/okp4-objectarium/src/contract.rs index eafb03a3..f91ef057 100644 --- a/contracts/okp4-objectarium/src/contract.rs +++ b/contracts/okp4-objectarium/src/contract.rs @@ -16,7 +16,7 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( - deps: DepsMut, + deps: DepsMut<'_>, _env: Env, info: MessageInfo, msg: InstantiateMsg, @@ -37,7 +37,7 @@ pub fn instantiate( #[cfg_attr(not(feature = "library"), entry_point)] pub fn execute( - deps: DepsMut, + deps: DepsMut<'_>, _env: Env, info: MessageInfo, msg: ExecuteMsg, @@ -65,7 +65,7 @@ pub mod execute { use std::any::type_name; pub fn store_object( - deps: DepsMut, + deps: DepsMut<'_>, info: MessageInfo, data: Binary, pin: bool, @@ -75,7 +75,7 @@ pub mod execute { let bucket = BUCKET.load(deps.storage)?; let compressions = &bucket.config.accepted_compression_algorithms; let compression: CompressionAlgorithm = compression_algorithm - .map(|a| a.into()) + .map(Into::into) .or_else(|| compressions.first().cloned()) .unwrap_or(CompressionAlgorithm::Passthrough); @@ -109,7 +109,7 @@ pub mod execute { .config .accepted_compression_algorithms .into_iter() - .map(|a| a.into()) + .map(Into::into) .collect(), ) .into()); @@ -123,7 +123,7 @@ pub mod execute { } let compressed_data = compression.compress(&data.0)?; - data_path.save(deps.storage, &compressed_data.to_vec())?; + data_path.save(deps.storage, &compressed_data)?; // store object let compressed_size = (compressed_data.len() as u128).into(); @@ -165,7 +165,7 @@ pub mod execute { } pub fn pin_object( - deps: DepsMut, + deps: DepsMut<'_>, info: MessageInfo, object_id: ObjectId, ) -> Result { @@ -210,7 +210,7 @@ pub mod execute { } pub fn unpin_object( - deps: DepsMut, + deps: DepsMut<'_>, info: MessageInfo, object_id: ObjectId, ) -> Result { @@ -235,7 +235,7 @@ pub mod execute { } pub fn forget_object( - deps: DepsMut, + deps: DepsMut<'_>, info: MessageInfo, object_id: ObjectId, ) -> Result { @@ -271,7 +271,7 @@ pub mod execute { } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result { +pub fn query(deps: Deps<'_>, _env: Env, msg: QueryMsg) -> Result { Ok(match msg { QueryMsg::Bucket {} => to_binary(&query::bucket(deps)?), QueryMsg::Object { id } => to_binary(&query::object(deps, id)?), @@ -297,7 +297,7 @@ pub mod query { use crate::pagination::{PaginationHandler, QueryPage}; use cosmwasm_std::{Addr, Order}; - pub fn bucket(deps: Deps) -> Result { + pub fn bucket(deps: Deps<'_>) -> Result { let bucket = BUCKET.load(deps.storage)?; Ok(BucketResponse { @@ -308,13 +308,13 @@ pub mod query { }) } - pub fn object(deps: Deps, object_id: ObjectId) -> Result { + pub fn object(deps: Deps<'_>, object_id: ObjectId) -> Result { let id: Hash = object_id.try_into()?; let object = objects().load(deps.storage, id)?; Ok((&object).into()) } - pub fn data(deps: Deps, object_id: ObjectId) -> Result { + pub fn data(deps: Deps<'_>, object_id: ObjectId) -> Result { let id: Hash = object_id.try_into()?; let compression = objects().load(deps.storage, id.clone())?.compression; let data = DATA.load(deps.storage, id)?; @@ -323,7 +323,7 @@ pub mod query { } pub fn fetch_objects( - deps: Deps, + deps: Deps<'_>, address: Option, after: Option, first: Option, @@ -333,7 +333,7 @@ pub mod query { _ => None, }; - let handler: PaginationHandler = + let handler: PaginationHandler<'_, Object, Hash> = PaginationHandler::from(BUCKET.load(deps.storage)?.pagination); let page: (Vec, PageInfo) = handler.query_page( @@ -351,13 +351,13 @@ pub mod query { )?; Ok(ObjectsResponse { - data: page.0.iter().map(|object| object.into()).collect(), + data: page.0.iter().map(Into::into).collect(), page_info: page.1, }) } pub fn object_pins( - deps: Deps, + deps: Deps<'_>, object_id: ObjectId, after: Option, first: Option, @@ -365,7 +365,7 @@ pub mod query { let id: Hash = object_id.try_into()?; objects().load(deps.storage, id.clone())?; - let handler: PaginationHandler = + let handler: PaginationHandler<'_, Pin, (Hash, Addr)> = PaginationHandler::from(BUCKET.load(deps.storage)?.pagination); let page: (Vec, PageInfo) = handler.query_page_cursor_fn( diff --git a/contracts/okp4-objectarium/src/crypto.rs b/contracts/okp4-objectarium/src/crypto.rs index a5f76290..edcc9c20 100644 --- a/contracts/okp4-objectarium/src/crypto.rs +++ b/contracts/okp4-objectarium/src/crypto.rs @@ -113,7 +113,7 @@ impl<'a> PrimaryKey<'a> for Hash { type Suffix = Self; type SuperSuffix = Self; - fn key(&self) -> Vec { + fn key(&self) -> Vec> { vec![Key::Ref(self.0.as_ref())] } } @@ -137,7 +137,7 @@ impl KeyDeserialize for &Hash { } impl<'a> Prefixer<'a> for Hash { - fn prefix(&self) -> Vec { + fn prefix(&self) -> Vec> { vec![Key::Ref(self.0.as_ref())] } } diff --git a/contracts/okp4-objectarium/src/cursor.rs b/contracts/okp4-objectarium/src/cursor.rs index 6151518a..7b7b8c5c 100644 --- a/contracts/okp4-objectarium/src/cursor.rs +++ b/contracts/okp4-objectarium/src/cursor.rs @@ -28,7 +28,7 @@ impl AsCursor for Object { fn decode_cursor(cursor: Cursor) -> StdResult { bs58::decode(cursor) .into_vec() - .map(|e| e.into()) + .map(Into::into) .map_err(|err| StdError::parse_err("Cursor", err)) } } diff --git a/contracts/okp4-objectarium/src/pagination.rs b/contracts/okp4-objectarium/src/pagination.rs index 1e10f8cb..a51b7526 100644 --- a/contracts/okp4-objectarium/src/pagination.rs +++ b/contracts/okp4-objectarium/src/pagination.rs @@ -39,7 +39,7 @@ pub trait QueryPage<'a, T, PK> { first: Option, ) -> StdResult<(Vec, PageInfo)> where - I: FnOnce(Option>) -> Box> + 'a>; + I: FnOnce(Option>) -> Box> + 'a>; } impl<'a, T, PK> QueryPage<'a, T, PK> for PaginationHandler<'a, T, PK> @@ -54,12 +54,12 @@ where first: Option, ) -> StdResult<(Vec, PageInfo)> where - I: FnOnce(Option>) -> Box> + 'a>, + I: FnOnce(Option>) -> Box> + 'a>, { self.query_page_cursor_fn( iter_fn, |c| T::decode_cursor(c), - |i| i.encode_cursor(), + AsCursor::encode_cursor, after, first, ) @@ -90,7 +90,7 @@ where first: Option, ) -> StdResult<(Vec, PageInfo)> where - I: FnOnce(Option>) -> Box> + 'a>, + I: FnOnce(Option>) -> Box> + 'a>, CD: FnOnce(Cursor) -> StdResult, CE: FnOnce(&T) -> Cursor, { @@ -109,10 +109,7 @@ where items.pop(); } - let cursor = items - .last() - .map(cursor_enc_fn) - .unwrap_or_else(|| "".to_string()); + let cursor = items.last().map_or_else(String::new, cursor_enc_fn); Ok(( items, diff --git a/contracts/okp4-objectarium/src/state.rs b/contracts/okp4-objectarium/src/state.rs index cbc67e94..96b35703 100644 --- a/contracts/okp4-objectarium/src/state.rs +++ b/contracts/okp4-objectarium/src/state.rs @@ -9,7 +9,7 @@ use cw_storage_plus::{Index, IndexList, IndexedMap, Item, Map, MultiIndex}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -pub const DATA: Map> = Map::new("DATA"); +pub const DATA: Map<'_, Hash, Vec> = Map::new("DATA"); #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] pub struct Bucket { @@ -254,7 +254,7 @@ impl TryFrom for Pagination { } } -pub const BUCKET: Item = Item::new("bucket"); +pub const BUCKET: Item<'_, Bucket> = Item::new("bucket"); #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] pub struct Object { @@ -291,7 +291,8 @@ pub struct ObjectIndexes<'a> { impl IndexList for ObjectIndexes<'_> { fn get_indexes(&'_ self) -> Box> + '_> { - Box::new(vec![&self.owner as &dyn Index].into_iter()) + let owner: &dyn Index = &self.owner; + Box::new(vec![owner].into_iter()) } } @@ -318,7 +319,8 @@ pub struct PinIndexes<'a> { impl IndexList for PinIndexes<'_> { fn get_indexes(&'_ self) -> Box> + '_> { - Box::new(vec![&self.object as &dyn Index].into_iter()) + let object: &dyn Index = &self.object; + Box::new(vec![object].into_iter()) } } diff --git a/packages/okp4-logic-bindings/src/term_parser.rs b/packages/okp4-logic-bindings/src/term_parser.rs index 4f7f59e5..06f0361b 100644 --- a/packages/okp4-logic-bindings/src/term_parser.rs +++ b/packages/okp4-logic-bindings/src/term_parser.rs @@ -88,7 +88,7 @@ impl<'a> Parser<'a> { loop { match self.peek() { Some(t) if [b'[', b'(', b'\'', b'"', b' '].contains(&t) => { - Err(TermParseError::UnexpectedValueToken(char::from(t)))? + Err(TermParseError::UnexpectedValueToken(char::from(t)))?; } Some(b) if ![b']', b')', b','].contains(&b) => { self.eat_char(); @@ -178,8 +178,7 @@ impl<'a> Parser<'a> { } if values.len() == 1 { - let val = values.first().unwrap(); - return Ok(val.clone()); + return Ok(values[0].clone()); } Ok(TermValue::Tuple(values)) diff --git a/packages/okp4-logic-bindings/src/testing/mock.rs b/packages/okp4-logic-bindings/src/testing/mock.rs index 2283dd4c..d382fc42 100644 --- a/packages/okp4-logic-bindings/src/testing/mock.rs +++ b/packages/okp4-logic-bindings/src/testing/mock.rs @@ -45,6 +45,6 @@ impl LogicQuerier { where LH: Fn(&LogicCustomQuery) -> QuerierResult, { - self.handler = Box::from(handler) + self.handler = Box::from(handler); } }