pub struct QuerySolution { /* private fields */ }
Expand description
Tuple associating variables and terms that are the result of a SPARQL query.
It is the equivalent of a row in SQL.
use sparesults::QuerySolution;
use oxrdf::{Variable, Literal};
let solution = QuerySolution::from((vec![Variable::new("foo")?, Variable::new("bar")?], vec![Some(Literal::from(1).into()), None]));
assert_eq!(solution.get("foo"), Some(&Literal::from(1).into())); // Get the value of the variable ?foo if it exists (here yes).
assert_eq!(solution.get(1), None); // Get the value of the second column if it exists (here no).
Implementations§
Source§impl QuerySolution
impl QuerySolution
Sourcepub fn get(&self, index: impl VariableSolutionIndex) -> Option<&Term>
pub fn get(&self, index: impl VariableSolutionIndex) -> Option<&Term>
Returns a value for a given position in the tuple (usize
) or a given variable name (&str
, Variable
or VariableRef
).
use sparesults::QuerySolution;
use oxrdf::{Variable, Literal};
let solution = QuerySolution::from((vec![Variable::new("foo")?, Variable::new("bar")?], vec![Some(Literal::from(1).into()), None]));
assert_eq!(solution.get("foo"), Some(&Literal::from(1).into())); // Get the value of the variable ?foo if it exists (here yes).
assert_eq!(solution.get(1), None); // Get the value of the second column if it exists (here no).
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
The number of variables which could be bound.
It is also the number of columns in the solutions table.
use oxrdf::{Literal, Variable};
use sparesults::QuerySolution;
let solution = QuerySolution::from((
vec![Variable::new("foo")?, Variable::new("bar")?],
vec![Some(Literal::from(1).into()), None],
));
assert_eq!(solution.len(), 2);
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Is there any variable bound in the table?
use oxrdf::{Literal, Variable};
use sparesults::QuerySolution;
let solution = QuerySolution::from((
vec![Variable::new("foo")?, Variable::new("bar")?],
vec![Some(Literal::from(1).into()), None],
));
assert!(!solution.is_empty());
let empty_solution = QuerySolution::from((
vec![Variable::new("foo")?, Variable::new("bar")?],
vec![None, None],
));
assert!(empty_solution.is_empty());
Sourcepub fn iter(&self) -> impl Iterator<Item = (&Variable, &Term)>
pub fn iter(&self) -> impl Iterator<Item = (&Variable, &Term)>
Returns an iterator over bound variables.
use oxrdf::{Literal, Variable};
use sparesults::QuerySolution;
let solution = QuerySolution::from((
vec![Variable::new("foo")?, Variable::new("bar")?],
vec![Some(Literal::from(1).into()), None],
));
assert_eq!(
solution.iter().collect::<Vec<_>>(),
vec![(&Variable::new("foo")?, &Literal::from(1).into())]
);
Sourcepub fn values(&self) -> &[Option<Term>]
pub fn values(&self) -> &[Option<Term>]
Returns the ordered slice of variable values.
use oxrdf::{Literal, Variable};
use sparesults::QuerySolution;
let solution = QuerySolution::from((
vec![Variable::new("foo")?, Variable::new("bar")?],
vec![Some(Literal::from(1).into()), None],
));
assert_eq!(solution.values(), &[Some(Literal::from(1).into()), None]);
Sourcepub fn variables(&self) -> &[Variable]
pub fn variables(&self) -> &[Variable]
Returns the ordered slice of the solution variables, bound or not.
use oxrdf::{Literal, Variable};
use sparesults::QuerySolution;
let solution = QuerySolution::from((
vec![Variable::new("foo")?, Variable::new("bar")?],
vec![Some(Literal::from(1).into()), None],
));
assert_eq!(
solution.variables(),
&[Variable::new("foo")?, Variable::new("bar")?]
);
Trait Implementations§
Source§impl Debug for QuerySolution
impl Debug for QuerySolution
Source§impl<V, S> From<(V, S)> for QuerySolution
impl<V, S> From<(V, S)> for QuerySolution
Source§fn from(_: (V, S)) -> QuerySolution
fn from(_: (V, S)) -> QuerySolution
Converts to this type from the input type.
Source§impl Index<&Variable> for QuerySolution
impl Index<&Variable> for QuerySolution
Source§impl Index<&str> for QuerySolution
impl Index<&str> for QuerySolution
Source§impl Index<Variable> for QuerySolution
impl Index<Variable> for QuerySolution
Source§impl Index<VariableRef<'_>> for QuerySolution
impl Index<VariableRef<'_>> for QuerySolution
Source§fn index(
&self,
index: VariableRef<'_>,
) -> &<QuerySolution as Index<VariableRef<'_>>>::Output
fn index( &self, index: VariableRef<'_>, ) -> &<QuerySolution as Index<VariableRef<'_>>>::Output
Performs the indexing (
container[index]
) operation. Read moreSource§impl Index<usize> for QuerySolution
impl Index<usize> for QuerySolution
Source§impl<'a> IntoIterator for &'a QuerySolution
impl<'a> IntoIterator for &'a QuerySolution
Source§impl PartialEq for QuerySolution
impl PartialEq for QuerySolution
impl Eq for QuerySolution
Auto Trait Implementations§
impl Freeze for QuerySolution
impl RefUnwindSafe for QuerySolution
impl Send for QuerySolution
impl Sync for QuerySolution
impl Unpin for QuerySolution
impl UnwindSafe for QuerySolution
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more