Skip to main content

oxigraph/io/
mod.rs

1//! Utilities to read and write RDF graphs and datasets using [OxRDF I/O](https://crates.io/crates/oxrdfio).
2//!
3//! The entry points of this module are the two [`RdfParser`] and [`RdfSerializer`] structs.
4//!
5//! Usage example converting a Turtle file to a N-Triples file:
6//! ```
7//! use oxigraph::io::{RdfFormat, RdfParser, RdfSerializer};
8//!
9//! let turtle_file = "@base <http://example.com/> .
10//! @prefix schema: <http://schema.org/> .
11//! <foo> a schema:Person ;
12//!     schema:name \"Foo\" .
13//! <bar> a schema:Person ;
14//!     schema:name \"Bar\" .";
15//!
16//! let ntriples_file = "<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
17//! <http://example.com/foo> <http://schema.org/name> \"Foo\" .
18//! <http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
19//! <http://example.com/bar> <http://schema.org/name> \"Bar\" .
20//! ";
21//!
22//! let mut serializer = RdfSerializer::from_format(RdfFormat::NTriples).for_writer(Vec::new());
23//! for quad in RdfParser::from_format(RdfFormat::Turtle).for_reader(turtle_file.as_bytes()) {
24//!     serializer.serialize_quad(&quad.unwrap()).unwrap();
25//! }
26//! assert_eq!(serializer.finish().unwrap(), ntriples_file.as_bytes());
27//! ```
28
29pub use oxrdfio::{
30    JsonLdProfile, JsonLdProfileSet, LoadedDocument, RdfFormat, RdfParseError, RdfParser,
31    RdfSerializer, RdfSyntaxError, ReaderQuadParser, SliceQuadParser, TextPosition,
32    WriterQuadSerializer,
33};