Expand description

Implementation of N-Triples, N-Quads, Turtle and TriG parsers.

RDF-star syntaxes are also supported, i.e. Turtle-star, TriG-star, N-Triples-star and N-Quads-star.

All the provided parsers work in streaming from a BufRead implementation. They do not rely on any dependencies outside of Rust standard library. The parsers are not protected against memory overflows. For example if the parsed content contains a literal string of 16 GB, 16 GB of memory will be allocated.

How to read a file foo.ttl and count the number of rdf:type triples:

use rio_turtle::{TurtleParser, TurtleError};
use rio_api::parser::TriplesParser;
use rio_api::model::NamedNode;
use std::io::BufReader;
use std::fs::File;
use oxiri::Iri;

let rdf_type = NamedNode { iri: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" };
let mut count = 0;
TurtleParser::new(BufReader::new(File::open("foo.ttl")?), Some(Iri::parse("file:foo.ttl".to_owned()).unwrap())).parse_all(&mut |t| {
    if t.predicate == rdf_type {
        count += 1;
    Ok(()) as Result<(), TurtleError>

Replace TurtleParser by NTriplesParser, NQuadsParser or TriGParser to read an N-Triples, N-Quads or TriG file instead.

NTriplesParser and NQuadsParser do not use the second argument of the new function that is the IRI of the file.


A TriG streaming parser parsing generalized quads.

A N-Quads and N-Quads-star streaming parser.

A N-Triples and N-Triples-star streaming parser.

A TriG formatter.

A TriG and TriG-star streaming parser.

Error that might be returned during parsing.

A Turtle formatter.

A Turtle and Turtle-star streaming parser.