diff --git a/lib/src/sparql/algebra.rs b/lib/src/sparql/algebra.rs index 9ebcb08d..445bb97c 100644 --- a/lib/src/sparql/algebra.rs +++ b/lib/src/sparql/algebra.rs @@ -9,6 +9,87 @@ use std::collections::BTreeSet; use std::fmt; use std::ops::Add; +#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)] +pub enum NamedNodeOrVariable { + NamedNode(NamedNode), + Variable(Variable), +} + +impl fmt::Display for NamedNodeOrVariable { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + NamedNodeOrVariable::NamedNode(node) => node.fmt(f), + NamedNodeOrVariable::Variable(var) => var.fmt(f), + } + } +} + +impl From for NamedNodeOrVariable { + fn from(node: NamedNode) -> Self { + NamedNodeOrVariable::NamedNode(node) + } +} + +impl From for NamedNodeOrVariable { + fn from(var: Variable) -> Self { + NamedNodeOrVariable::Variable(var) + } +} + +#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)] +pub enum TermOrVariable { + Term(Term), + Variable(Variable), +} + +impl fmt::Display for TermOrVariable { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + TermOrVariable::Term(term) => term.fmt(f), + TermOrVariable::Variable(var) => var.fmt(f), + } + } +} + +impl From for TermOrVariable { + fn from(node: NamedNode) -> Self { + TermOrVariable::Term(node.into()) + } +} + +impl From for TermOrVariable { + fn from(node: BlankNode) -> Self { + TermOrVariable::Term(node.into()) + } +} + +impl From for TermOrVariable { + fn from(literal: Literal) -> Self { + TermOrVariable::Term(literal.into()) + } +} + +impl From for TermOrVariable { + fn from(var: Variable) -> Self { + TermOrVariable::Variable(var) + } +} + +impl From for TermOrVariable { + fn from(term: Term) -> Self { + TermOrVariable::Term(term) + } +} + +impl From for TermOrVariable { + fn from(element: NamedNodeOrVariable) -> Self { + match element { + NamedNodeOrVariable::NamedNode(node) => TermOrVariable::Term(node.into()), + NamedNodeOrVariable::Variable(var) => TermOrVariable::Variable(var), + } + } +} + #[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)] pub struct StaticBindings { variables: Vec, diff --git a/lib/src/sparql/model.rs b/lib/src/sparql/model.rs index b8c33bc6..1b5c0c00 100644 --- a/lib/src/sparql/model.rs +++ b/lib/src/sparql/model.rs @@ -185,84 +185,3 @@ impl fmt::Display for Variable { write!(f, "?{}", self.name) } } - -#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)] -pub enum NamedNodeOrVariable { - NamedNode(NamedNode), - Variable(Variable), -} - -impl fmt::Display for NamedNodeOrVariable { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - NamedNodeOrVariable::NamedNode(node) => node.fmt(f), - NamedNodeOrVariable::Variable(var) => var.fmt(f), - } - } -} - -impl From for NamedNodeOrVariable { - fn from(node: NamedNode) -> Self { - NamedNodeOrVariable::NamedNode(node) - } -} - -impl From for NamedNodeOrVariable { - fn from(var: Variable) -> Self { - NamedNodeOrVariable::Variable(var) - } -} - -#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)] -pub enum TermOrVariable { - Term(Term), - Variable(Variable), -} - -impl fmt::Display for TermOrVariable { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - TermOrVariable::Term(term) => term.fmt(f), - TermOrVariable::Variable(var) => var.fmt(f), - } - } -} - -impl From for TermOrVariable { - fn from(node: NamedNode) -> Self { - TermOrVariable::Term(node.into()) - } -} - -impl From for TermOrVariable { - fn from(node: BlankNode) -> Self { - TermOrVariable::Term(node.into()) - } -} - -impl From for TermOrVariable { - fn from(literal: Literal) -> Self { - TermOrVariable::Term(literal.into()) - } -} - -impl From for TermOrVariable { - fn from(var: Variable) -> Self { - TermOrVariable::Variable(var) - } -} - -impl From for TermOrVariable { - fn from(term: Term) -> Self { - TermOrVariable::Term(term) - } -} - -impl From for TermOrVariable { - fn from(element: NamedNodeOrVariable) -> Self { - match element { - NamedNodeOrVariable::NamedNode(node) => TermOrVariable::Term(node.into()), - NamedNodeOrVariable::Variable(var) => TermOrVariable::Variable(var), - } - } -}