oxigraph::sparql::results

Struct WriterSolutionsSerializer

Source
pub struct WriterSolutionsSerializer<W>
where W: Write,
{ /* private fields */ }
Expand description

Allows writing query results into a Write implementation.

Could be built using a QueryResultsSerializer.

Do not forget to run the finish method to properly write the last bytes of the file.

This writer does unbuffered writes. You might want to use BufWriter to avoid that.

Example in TSV (the API is the same for JSON, XML and CSV):

use oxrdf::{LiteralRef, Variable, VariableRef};
use sparesults::{QueryResultsFormat, QueryResultsSerializer};
use std::iter::once;

let tsv_serializer = QueryResultsSerializer::from_format(QueryResultsFormat::Tsv);
let mut buffer = Vec::new();
let mut serializer = tsv_serializer.serialize_solutions_to_writer(
    &mut buffer,
    vec![Variable::new("foo")?, Variable::new("bar")?],
)?;
serializer.serialize(once((VariableRef::new("foo")?, LiteralRef::from("test"))))?;
serializer.finish()?;
assert_eq!(buffer, b"?foo\t?bar\n\"test\"\t\n");

Implementations§

Source§

impl<W> WriterSolutionsSerializer<W>
where W: Write,

Source

pub fn serialize<'a>( &mut self, solution: impl IntoIterator<Item = (impl Into<VariableRef<'a>>, impl Into<TermRef<'a>>)>, ) -> Result<(), Error>

Writes a solution.

Example in JSON (the API is the same for XML, CSV and TSV):

use sparesults::{QueryResultsFormat, QueryResultsSerializer, QuerySolution};
use oxrdf::{Literal, LiteralRef, Variable, VariableRef};
use std::iter::once;

let json_serializer = QueryResultsSerializer::from_format(QueryResultsFormat::Json);
let mut buffer = Vec::new();
let mut serializer = json_serializer.serialize_solutions_to_writer(&mut buffer, vec![Variable::new("foo")?, Variable::new("bar")?])?;
serializer.serialize(once((VariableRef::new("foo")?, LiteralRef::from("test"))))?;
serializer.serialize(&QuerySolution::from((vec![Variable::new("bar")?], vec![Some(Literal::from("test").into())])))?;
serializer.finish()?;
assert_eq!(buffer, br#"{"head":{"vars":["foo","bar"]},"results":{"bindings":[{"foo":{"type":"literal","value":"test"}},{"bar":{"type":"literal","value":"test"}}]}}"#);
Source

pub fn finish(self) -> Result<W, Error>

Writes the last bytes of the file.

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