oxigraph::sparql

Struct QuerySolution

Source
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

Source

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).
Source

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);
Source

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());
Source

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())]
);
Source

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]);
Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<V, S> From<(V, S)> for QuerySolution
where V: Into<Arc<[Variable]>>, S: Into<Vec<Option<Term>>>,

Source§

fn from(_: (V, S)) -> QuerySolution

Converts to this type from the input type.
Source§

impl Index<&Variable> for QuerySolution

Source§

type Output = Term

The returned type after indexing.
Source§

fn index( &self, index: &Variable, ) -> &<QuerySolution as Index<&Variable>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<&str> for QuerySolution

Source§

type Output = Term

The returned type after indexing.
Source§

fn index(&self, index: &str) -> &<QuerySolution as Index<&str>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<Variable> for QuerySolution

Source§

type Output = Term

The returned type after indexing.
Source§

fn index(&self, index: Variable) -> &<QuerySolution as Index<Variable>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<VariableRef<'_>> for QuerySolution

Source§

type Output = Term

The returned type after indexing.
Source§

fn index( &self, index: VariableRef<'_>, ) -> &<QuerySolution as Index<VariableRef<'_>>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<usize> for QuerySolution

Source§

type Output = Term

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &<QuerySolution as Index<usize>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a> IntoIterator for &'a QuerySolution

Source§

type Item = (&'a Variable, &'a Term)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <&'a QuerySolution as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for QuerySolution

Source§

fn eq(&self, other: &QuerySolution) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for QuerySolution

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V