From b7a12720a17b052aa08ef0d4b53d561cc1c91b40 Mon Sep 17 00:00:00 2001 From: Arnaud Mimart <33665250+amimart@users.noreply.github.com> Date: Wed, 28 Feb 2024 18:35:27 +0100 Subject: [PATCH] style(cognitarium): remove dead code --- contracts/okp4-cognitarium/src/msg.rs | 189 +------------------------- 1 file changed, 2 insertions(+), 187 deletions(-) diff --git a/contracts/okp4-cognitarium/src/msg.rs b/contracts/okp4-cognitarium/src/msg.rs index 0f11d04c..5ad0158b 100644 --- a/contracts/okp4-cognitarium/src/msg.rs +++ b/contracts/okp4-cognitarium/src/msg.rs @@ -1,7 +1,7 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{Binary, Uint128}; use derive_builder::Builder; -use std::collections::{BTreeMap, HashSet}; +use std::collections::BTreeMap; /// Instantiate message #[cw_serde] @@ -484,25 +484,6 @@ pub enum SimpleWhereCondition { TriplePattern(TriplePattern), } -pub trait HasVariables { - /// Returns the set of variables used in a triple pattern or template. - fn variables(&self) -> HashSet; - - /// Returns the set of variables used in a triple pattern or template as [SelectItem]. - fn as_select_item(&self) -> Vec { - self.variables() - .into_iter() - .map(SelectItem::Variable) - .collect() - } -} - -impl HasVariables for Vec { - fn variables(&self) -> HashSet { - self.iter().flat_map(HasVariables::variables).collect() - } -} - /// # TripleDeleteTemplate /// Represents a triple template to be deleted. #[cw_serde] @@ -515,16 +496,6 @@ pub struct TripleDeleteTemplate { pub object: VarOrNamedNodeOrLiteral, } -impl HasVariables for TripleDeleteTemplate { - fn variables(&self) -> HashSet { - var_util::merge_variables(&[ - self.subject.variable(), - self.predicate.variable(), - self.object.variable(), - ]) - } -} - /// # TripleConstructTemplate /// Represents a triple template to be forged for a construct query. #[cw_serde] @@ -537,16 +508,6 @@ pub struct TripleConstructTemplate { pub object: VarOrNodeOrLiteral, } -impl HasVariables for TripleConstructTemplate { - fn variables(&self) -> HashSet { - var_util::merge_variables(&[ - self.subject.variable(), - self.predicate.variable(), - self.object.variable(), - ]) - } -} - /// # TriplePattern /// Represents a triple pattern in a [SimpleWhereCondition]. #[cw_serde] @@ -559,33 +520,6 @@ pub struct TriplePattern { pub object: VarOrNodeOrLiteral, } -impl HasVariables for TriplePattern { - fn variables(&self) -> HashSet { - var_util::merge_variables(&[ - self.subject.variable(), - self.predicate.variable(), - self.object.variable(), - ]) - } -} - -trait MaybeVariable { - fn variable(&self) -> Option<&str>; -} - -mod var_util { - use std::collections::HashSet; - - pub fn merge_variables(maybe_vars: &[Option<&str>]) -> HashSet { - maybe_vars - .iter() - .copied() - .flatten() - .map(str::to_string) - .collect() - } -} - /// # VarOrNode /// Represents either a variable or a node. #[cw_serde] @@ -598,15 +532,6 @@ pub enum VarOrNode { Node(Node), } -impl MaybeVariable for VarOrNode { - fn variable(&self) -> Option<&str> { - match self { - Self::Variable(v) => Some(v.as_str()), - _ => None, - } - } -} - /// # VarOrNamedNode { /// Represents either a variable or a named node (IRI). #[cw_serde] @@ -619,15 +544,6 @@ pub enum VarOrNamedNode { NamedNode(IRI), } -impl MaybeVariable for VarOrNamedNode { - fn variable(&self) -> Option<&str> { - match self { - Self::Variable(v) => Some(v.as_str()), - _ => None, - } - } -} - /// # VarOrNodeOrLiteral /// Represents either a variable, a node or a literal. #[cw_serde] @@ -644,15 +560,6 @@ pub enum VarOrNodeOrLiteral { Literal(Literal), } -impl MaybeVariable for VarOrNodeOrLiteral { - fn variable(&self) -> Option<&str> { - match self { - Self::Variable(v) => Some(v.as_str()), - _ => None, - } - } -} - /// # VarOrNamedNodeOrLiteral /// Represents either a variable, a named node or a literal. #[cw_serde] @@ -669,15 +576,6 @@ pub enum VarOrNamedNodeOrLiteral { Literal(Literal), } -impl MaybeVariable for VarOrNamedNodeOrLiteral { - fn variable(&self) -> Option<&str> { - match self { - Self::Variable(v) => Some(v.as_str()), - _ => None, - } - } -} - /// # Literal /// An RDF [literal](https://www.w3.org/TR/rdf11-concepts/#dfn-literal). #[cw_serde] @@ -717,14 +615,7 @@ pub enum Node { #[cfg(test)] mod tests { - use super::*; - use crate::msg::Literal::Simple; - use crate::msg::Node::{BlankNode, NamedNode}; - use crate::msg::IRI::{Full, Prefixed}; - use crate::msg::{ - HasVariables, InstantiateMsg, StoreLimitsInput, TriplePattern, VarOrNode, - VarOrNodeOrLiteral, - }; + use crate::msg::{InstantiateMsg, StoreLimitsInput}; use cosmwasm_std::Uint128; use schemars::_serde_json; @@ -759,80 +650,4 @@ mod tests { assert_eq!(msg.limits.max_insert_data_byte_size, Uint128::MAX); assert_eq!(msg.limits.max_insert_data_triple_count, Uint128::MAX); } - - #[test] - fn variables_from_triple_pattern() { - let (s, p, o) = ("s".to_string(), "p".to_string(), "o".to_string()); - let (node, prefixed, literal) = ( - "node".to_string(), - "a:node".to_string(), - "literal".to_string(), - ); - - let cases = vec![ - ( - TriplePattern { - subject: VarOrNode::Variable(s.clone()), - predicate: VarOrNamedNode::Variable(p.clone()), - object: VarOrNodeOrLiteral::Variable(o.clone()), - }, - vec![s.clone(), p.clone(), o.clone()], - ), - ( - TriplePattern { - subject: VarOrNode::Node(NamedNode(Full(node.clone()))), - predicate: VarOrNamedNode::Variable(p.clone()), - object: VarOrNodeOrLiteral::Variable(o.clone()), - }, - vec![p.clone(), o.clone()], - ), - ( - TriplePattern { - subject: VarOrNode::Node(NamedNode(Prefixed(prefixed.clone()))), - predicate: VarOrNamedNode::Variable(p.clone()), - object: VarOrNodeOrLiteral::Variable(o.clone()), - }, - vec![p.clone(), o.clone()], - ), - ( - TriplePattern { - subject: VarOrNode::Node(BlankNode(node.clone())), - predicate: VarOrNamedNode::Variable(p.clone()), - object: VarOrNodeOrLiteral::Variable(o.clone()), - }, - vec![p.clone(), o.clone()], - ), - ( - TriplePattern { - subject: VarOrNode::Variable(s.clone()), - predicate: VarOrNamedNode::NamedNode(Full(node.clone())), - object: VarOrNodeOrLiteral::Variable(o.clone()), - }, - vec![s.clone(), o], - ), - ( - TriplePattern { - subject: VarOrNode::Variable(s.clone()), - predicate: VarOrNamedNode::Variable(p.clone()), - object: VarOrNodeOrLiteral::Literal(Simple(literal.clone())), - }, - vec![s, p], - ), - ( - TriplePattern { - subject: VarOrNode::Node(BlankNode(node)), - predicate: VarOrNamedNode::NamedNode(Prefixed(prefixed)), - object: VarOrNodeOrLiteral::Literal(Simple(literal)), - }, - vec![], - ), - ]; - - for (triple_pattern, expected) in cases { - assert_eq!( - triple_pattern.variables(), - HashSet::from_iter(expected.into_iter()) - ); - } - } }