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
Noneindicates that the variable is unbound in this solution, which can occur with OPTIONAL patterns or UNION queries).
§Type Parameters
S- The RDF graph type implementingRdf
Implementations§
Source§impl<S: Rdf> QuerySolution<S>
impl<S: Rdf> QuerySolution<S>
Sourcepub fn new(
variables: Vec<VarName>,
values: Vec<Option<S::Term>>,
) -> QuerySolution<S>
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 namesvalues- The ordered list of optional term values
Sourcepub fn find_solution(
&self,
index: impl VariableSolutionIndex<S>,
) -> Option<&S::Term>
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)
Sourcepub fn variables_iter(&self) -> impl Iterator<Item = &VarName>
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).
Sourcepub fn convert<T: Rdf, F>(&self, cnv_term: F) -> QuerySolution<T>
pub fn convert<T: Rdf, F>(&self, cnv_term: F) -> QuerySolution<T>
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 typeF- The term conversion function type
§Arguments
cnv_term- A function that converts terms fromS::TermtoT::Term
Trait Implementations§
Source§impl<S: Clone + Rdf> Clone for QuerySolution<S>
impl<S: Clone + Rdf> Clone for QuerySolution<S>
Source§fn clone(&self) -> QuerySolution<S>
fn clone(&self) -> QuerySolution<S>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<S: Rdf, V: Into<Vec<VarName>>, T: Into<Vec<Option<S::Term>>>> From<(V, T)> for QuerySolution<S>
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
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>
impl<S: Rdf> Serialize for QuerySolution<S>
Source§fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>where
Ser: Serializer,
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.