Struct WriterSolutionsSerializer
pub struct WriterSolutionsSerializer<W>where
W: Write,{
formatter: WriterSolutionsSerializerKind<W>,
}
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");
Fields§
§formatter: WriterSolutionsSerializerKind<W>
Implementations§
§impl<W> WriterSolutionsSerializer<W>where
W: Write,
impl<W> WriterSolutionsSerializer<W>where
W: Write,
pub fn serialize<'a>(
&mut self,
solution: impl IntoIterator<Item = (impl Into<VariableRef<'a>>, impl Into<TermRef<'a>>)>,
) -> Result<(), Error>
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"}}]}}"#);
Auto Trait Implementations§
impl<W> Freeze for WriterSolutionsSerializer<W>where
W: Freeze,
impl<W> RefUnwindSafe for WriterSolutionsSerializer<W>where
W: RefUnwindSafe,
impl<W> Send for WriterSolutionsSerializer<W>where
W: Send,
impl<W> Sync for WriterSolutionsSerializer<W>where
W: Sync,
impl<W> Unpin for WriterSolutionsSerializer<W>where
W: Unpin,
impl<W> UnwindSafe for WriterSolutionsSerializer<W>where
W: UnwindSafe,
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
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
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
§fn deserialize(
&self,
deserializer: &mut D,
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>
Deserializes using the given deserializer
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn 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>
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)
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)
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
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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