Skip to main content

QuerySolution

Struct QuerySolution 

Source
pub struct QuerySolution<S: Rdf> { /* private fields */ }
Expand description

Represents a single solution from a SPARQL SELECT query.

A query solution is analogous to a row in a SQL result set. It contains bindings for SPARQL variables, mapping each variable to an RDF term (or indicating the variable is unbound).

Each solution maintains:

  • An ordered list of variable names (the “columns”)
  • A corresponding list of optional term values (a value of None indicates that the variable is unbound in this solution, which can occur with OPTIONAL patterns or UNION queries).

§Type Parameters

  • S - The RDF graph type implementing Rdf

Implementations§

Source§

impl<S: Rdf> QuerySolution<S>

Source

pub fn new( variables: Vec<VarName>, values: Vec<Option<S::Term>>, ) -> QuerySolution<S>

Creates a new query solution from variables and values.

The variables and values vectors must have the same length, with each value corresponding to the variable at the same index.

§Arguments
  • variables - The ordered list of variable names
  • values - The ordered list of optional term values
Source

pub fn find_solution( &self, index: impl VariableSolutionIndex<S>, ) -> Option<&S::Term>

Finds and returns the term bound to a variable in this solution.

This method accepts any type implementing VariableSolutionIndex, allowing lookup by variable name, position, or custom index types.

§Arguments
  • index - The variable index (name string, position, or VarName reference)
Source

pub fn variables_iter(&self) -> impl Iterator<Item = &VarName>

Returns an iterator over the variable names in this solution.

The iterator yields references to VarName instances in the order they appear in the solution (matching the SELECT clause order).

Source

pub fn variables(&self) -> &Vec<VarName>

Returns a reference to the vector of variable names.

Source

pub fn convert<T: Rdf, F>(&self, cnv_term: F) -> QuerySolution<T>
where F: Fn(&S::Term) -> T::Term,

Converts this solution to use a different RDF type.

This method transforms a solution from one RDF implementation to another by applying a conversion function to each bound term. The variable names are preserved, and unbound variables remain unbound.

§Type Parameters
  • T - The target RDF type
  • F - The term conversion function type
§Arguments
  • cnv_term - A function that converts terms from S::Term to T::Term
Source

pub fn show(&self) -> String

Returns a human-readable string representation of this solution.

The output shows each variable with its bound value (or “()” for unbound variables), one per line in the format: ?variable -> value

Trait Implementations§

Source§

impl<S: Clone + Rdf> Clone for QuerySolution<S>
where S::Term: Clone,

Source§

fn clone(&self) -> QuerySolution<S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: Debug + Rdf> Debug for QuerySolution<S>
where S::Term: Debug,

Source§

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

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

impl<S: Rdf, V: Into<Vec<VarName>>, T: Into<Vec<Option<S::Term>>>> From<(V, T)> for QuerySolution<S>

Source§

fn from((v, s): (V, T)) -> Self

Constructs a query solution from a tuple of variables and values.

This convenience implementation allows creating solutions using tuple syntax, automatically converting compatible types into the required vector types.

§Arguments
  • Tuple of (variables, values) where both elements are convertible to their respective vector types
Source§

impl<S: Rdf> Serialize for QuerySolution<S>

Source§

fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where Ser: Serializer,

Serializes the query solution as a map of variable names to term strings.

Unbound variables (None values) are omitted from the serialized output rather than being represented as null. This matches common SPARQL JSON result format conventions.

Auto Trait Implementations§

§

impl<S> Freeze for QuerySolution<S>

§

impl<S> RefUnwindSafe for QuerySolution<S>
where <S as Rdf>::Term: RefUnwindSafe,

§

impl<S> Send for QuerySolution<S>
where <S as Rdf>::Term: Send,

§

impl<S> Sync for QuerySolution<S>
where <S as Rdf>::Term: Sync,

§

impl<S> Unpin for QuerySolution<S>
where <S as Rdf>::Term: Unpin,

§

impl<S> UnsafeUnpin for QuerySolution<S>

§

impl<S> UnwindSafe for QuerySolution<S>
where <S as Rdf>::Term: UnwindSafe,

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

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> PolicyExt for T
where T: ?Sized,

Source§

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
Source§

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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