Skip to content

Oxiland 0.2 I/O API proposal

Status: accepted with ADR-007 and ADR-008
Milestone: 0.2

Happy path

use oxiland::io::{Parser, Serializer, Syntax};
use oxiland::Model;

fn main() -> oxiland::Result<()> {
    let model = Model::new()?;
    Parser::for_syntax(Syntax::Turtle)
        .base_iri("https://example.com/")?
        .load_collecting(&model, b"<alice> <name> \"Alice\" .".as_slice())?;

    let turtle = Serializer::for_syntax(Syntax::Turtle)
        .with_prefix("ex", "https://example.com/")?
        .serialize_model_to_string(&model)?;
    println!("{turtle}");
    Ok(())
}

Streaming and early stop

use oxiland::io::{Parser, Syntax};

fn first_quad(input: &[u8]) -> oxiland::Result<oxiland::terms::Quad> {
    Parser::for_syntax(Syntax::NTriples)
        .parse_slice(input)?
        .next()
        .ok_or_else(|| oxiland::Error::Unsupported("empty input".into()))?
}

Failure paths

  • Unknown syntax name/MIME/extension → Error::Unsupported (no silent guess).
  • Malformed RDF → Error::Parse with optional SourceLocation.
  • Progressive load_into after a valid prefix → model retains inserted quads; error text notes partial load (ADR-007).
  • load_collecting → buffers successful quads and inserts only on full success.
  • Named-graph serialization to Turtle/N-Triples/RDF/XML → Error::Unsupported.
  • Reader/writer failures → Error::Io.

Graph targets

  • GraphTarget::DefaultGraph — emit default-graph quads and reject named-graph input (including TriG/N-Quads named graphs).
  • GraphTarget::Named(g) — remap the syntax default graph into g and reject input quads that name a different graph (same-named quads are kept).
  • GraphTarget::Dataset — preserve named graphs from TriG/N-Quads; rejected for graph-only syntaxes.

Redland → Oxiland I/O migration

Redland concept Oxiland 0.2
librdf_new_parser(world, name, mime, type_uri) Syntax::from_name / from_media_type then Parser::for_syntax
librdf_parser_parse_*_as_stream Parser::parse_reader / parse_str / parse_path
librdf_parser_parse_*_into_model Parser::load_into (progressive) or load_collecting
Parser guess / content sniff Unsupported; use explicit Syntax or parse_path_with_extension
librdf_new_serializer Serializer::for_syntax
librdf_serializer_set_namespace Serializer::with_prefix
Serialize model to string/file serialize_model_to_string / serialize_model_to_path
N3 / JSON-LD factories Unsupported or deferred; see format matrix

Oxigraph primitives previously re-exported at oxiland::io now live under oxiland::io::primitives.