pub struct WriterJsonLdSerializer<W: Write> { /* private fields */ }
Expand description
Serializes a JSON-LD file to a Write
implementation.
Can be built using JsonLdSerializer::for_writer
.
use oxrdf::{GraphNameRef, LiteralRef, NamedNodeRef, QuadRef};
use oxrdf::vocab::rdf;
use oxjsonld::JsonLdSerializer;
let mut serializer = JsonLdSerializer::new().with_prefix("schema", "http://schema.org/")?.for_writer(Vec::new());
serializer.serialize_quad(QuadRef::new(
NamedNodeRef::new("http://example.com#me")?,
rdf::TYPE,
NamedNodeRef::new("http://schema.org/Person")?,
GraphNameRef::DefaultGraph
))?;
serializer.serialize_quad(QuadRef::new(
NamedNodeRef::new("http://example.com#me")?,
NamedNodeRef::new("http://schema.org/name")?,
LiteralRef::new_language_tagged_literal_unchecked("Foo Bar", "en"),
GraphNameRef::DefaultGraph
))?;
assert_eq!(
b"{\"@context\":{\"schema\":\"http://schema.org/\"},\"@graph\":[{\"@id\":\"http://example.com#me\",\"http://www.w3.org/1999/02/22-rdf-syntax-ns#type\":[{\"@id\":\"http://schema.org/Person\"}],\"http://schema.org/name\":[{\"@language\":\"en\",\"@value\":\"Foo Bar\"}]}]}",
serializer.finish()?.as_slice()
);
Implementations§
Auto Trait Implementations§
impl<W> Freeze for WriterJsonLdSerializer<W>where
W: Freeze,
impl<W> RefUnwindSafe for WriterJsonLdSerializer<W>where
W: RefUnwindSafe,
impl<W> Send for WriterJsonLdSerializer<W>where
W: Send,
impl<W> Sync for WriterJsonLdSerializer<W>where
W: Sync,
impl<W> Unpin for WriterJsonLdSerializer<W>where
W: Unpin,
impl<W> UnwindSafe for WriterJsonLdSerializer<W>where
W: UnwindSafe,
Blanket Implementations§
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