Struct QuerySolution

pub struct QuerySolution {
    variables: Arc<[Variable]>,
    values: Vec<Option<Term>>,
}
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).

Fieldsยง

ยงvariables: Arc<[Variable]>ยงvalues: Vec<Option<Term>>

Implementationsยง

ยง

impl QuerySolution

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

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

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

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

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

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ยง

ยง

impl Debug for QuerySolution

ยง

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

Formats the value using the given formatter. Read more
ยง

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

ยง

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

Converts to this type from the input type.
ยง

impl Index<&Variable> for QuerySolution

ยง

type Output = Term

The returned type after indexing.
ยง

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

Performs the indexing (container[index]) operation. Read more
ยง

impl Index<&str> for QuerySolution

ยง

type Output = Term

The returned type after indexing.
ยง

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

Performs the indexing (container[index]) operation. Read more
ยง

impl Index<Variable> for QuerySolution

ยง

type Output = Term

The returned type after indexing.
ยง

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

Performs the indexing (container[index]) operation. Read more
ยง

impl Index<VariableRef<'_>> for QuerySolution

ยง

type Output = Term

The returned type after indexing.
ยง

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

Performs the indexing (container[index]) operation. Read more
ยง

impl Index<usize> for QuerySolution

ยง

type Output = Term

The returned type after indexing.
ยง

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

Performs the indexing (container[index]) operation. Read more
ยง

impl<'a> IntoIterator for &'a QuerySolution

ยง

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

The type of the elements being iterated over.
ยง

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
ยง

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

Creates an iterator from a value. Read more
ยง

impl PartialEq for QuerySolution

ยง

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.
ยง

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
ยง

impl<T> ArchivePointee for T

ยง

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
ยง

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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
ยง

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

ยง

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
ยง

impl<T> Downcast for T
where T: Any,

ยง

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
ยง

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
ยง

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Anyโ€™s vtable from &Traitโ€™s.
ยง

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Anyโ€™s vtable from &mut Traitโ€™s.
ยง

impl<T> DowncastSend for T
where T: Any + Send,

ยง

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
ยง

impl<T> DowncastSync for T
where T: Any + Send + Sync,

ยง

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
ยง

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
ยง

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

ยง

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

Checks if this value is equivalent to the given key. Read more
ยง

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

ยง

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

Compare self to key and return true if they are equal.
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

ยง

impl<T> Instrument for T

ยง

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
ยง

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Sourceยง

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Sourceยง

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
ยง

impl<T> Pointable for T

ยง

const ALIGN: usize

The alignment of pointer.
ยง

type Init = T

The type for initializers.
ยง

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
ยง

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
ยง

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
ยง

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
ยง

impl<T> Pointee for T

ยง

type Metadata = ()

The type for metadata in pointers and references to Self.
ยง

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

ยง

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
ยง

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
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.
ยง

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

ยง

fn vzip(self) -> V

ยง

impl<T> WithSubscriber for T

ยง

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
ยง

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
ยง

impl<T> ErasedDestructor for T
where T: 'static,

ยง

impl<T> Fruit for T
where T: Send + Downcast,