From 34a3db7a7fc6fa7eb40e1c1f5ea9b85a0bee5519 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Champin Date: Thu, 27 Aug 2020 16:41:58 +0200 Subject: [PATCH] destruct methods for SparqlResult --- api/src/sparql.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/api/src/sparql.rs b/api/src/sparql.rs index 8b9ed89d..54de2a49 100644 --- a/api/src/sparql.rs +++ b/api/src/sparql.rs @@ -42,6 +42,42 @@ where Triples(T::TriplesResult), } +impl SparqlResult +where + T: SparqlDataset + ?Sized, +{ + /// Get this result as a `Bindings`. + /// + /// # Panics + /// This will panic if `self` is actually of another kind. + pub fn into_bindings(self) -> T::BindingsResult { + match self { + SparqlResult::Bindings(b) => b, + _ => panic!("This SparqlResult is not a Bindings"), + } + } + /// Get this result as a `Boolean`. + /// + /// # Panics + /// This will panic if `self` is actually of another kind. + pub fn into_boolean(self) -> bool { + match self { + SparqlResult::Boolean(b) => b, + _ => panic!("This SparqlResult is not a Boolean"), + } + } + /// Get this result as a `Triples`. + /// + /// # Panics + /// This will panic if `self` is actually of another kind. + pub fn into_triples(self) -> T::TriplesResult { + match self { + SparqlResult::Triples(t) => t, + _ => panic!("This SparqlResult is not a Triples"), + } + } +} + /// The result of executing a SPARQL SELECT query pub trait SparqlBindings: IntoIterator>, D::SparqlError>>