diff --git a/lib/src/sparql/algebra.rs b/lib/src/sparql/algebra.rs index e84f55a9..dee08ec6 100644 --- a/lib/src/sparql/algebra.rs +++ b/lib/src/sparql/algebra.rs @@ -36,15 +36,7 @@ impl Query { /// Parses a SPARQL query with an optional base IRI to resolve relative IRIs in the query. pub fn parse(query: &str, base_iri: Option<&str>) -> Result { let query = spargebra::Query::parse(query, base_iri)?; - Ok(Self { - dataset: QueryDataset::from_algebra(match &query { - spargebra::Query::Select { dataset, .. } - | spargebra::Query::Construct { dataset, .. } - | spargebra::Query::Describe { dataset, .. } - | spargebra::Query::Ask { dataset, .. } => dataset, - }), - inner: query, - }) + Ok(query.into()) } /// Returns [the query dataset specification](https://www.w3.org/TR/sparql11-query/#specifyingDataset) @@ -88,6 +80,20 @@ impl<'a> TryFrom<&'a String> for Query { } } +impl From for Query { + fn from(query: spargebra::Query) -> Self { + Self { + dataset: QueryDataset::from_algebra(match &query { + spargebra::Query::Select { dataset, .. } + | spargebra::Query::Construct { dataset, .. } + | spargebra::Query::Describe { dataset, .. } + | spargebra::Query::Ask { dataset, .. } => dataset, + }), + inner: query, + } + } +} + /// A parsed [SPARQL update](https://www.w3.org/TR/sparql11-update/). /// /// ```