Skip to main content

GraphExport

Struct GraphExport 

Source
pub struct GraphExport<'a> { /* private fields */ }
Expand description

GraphExport provides RDF serialization and export operations.

Uses Oxigraph’s RdfSerializer API following core team best practices for efficient and format-compliant RDF serialization.

Supports exporting graphs to files and streams in all RDF formats:

  • Turtle (.ttl) - Human-readable format with prefix support
  • N-Triples (.nt) - Line-based format with full IRIs
  • RDF/XML (.rdf, .xml) - XML-based RDF serialization
  • TriG (.trig) - Turtle format with named graph support
  • N-Quads (.nq) - N-Triples format with named graph support

§Examples

§Export to file

use crate::graph::{Graph, GraphExport};
use oxigraph::io::RdfFormat;

let graph = Graph::new()?;
graph.insert_turtle(r#"
    @prefix ex: <http://example.org/> .
    ex:alice a ex:Person .
"#)?;

let export = GraphExport::new(&graph);
export.write_to_file("output.ttl", RdfFormat::Turtle)?;

§Export to string

use crate::graph::{Graph, GraphExport};
use oxigraph::io::RdfFormat;

let graph = Graph::new()?;
let export = GraphExport::new(&graph);

let turtle = export.write_to_string(RdfFormat::Turtle)?;
println!("{}", turtle);

Implementations§

Source§

impl<'a> GraphExport<'a>

Source

pub fn new(graph: &'a Graph) -> Self

Create a new GraphExport instance for the given graph.

Source

pub fn write_to_file<P: AsRef<Path>>( &self, path: P, format: RdfFormat, ) -> Result<()>

Write the graph to a file in the specified format.

§Arguments
  • path - Path to the output file
  • format - RDF format to use
§Errors

Returns an error if:

  • The file cannot be created or written
  • The format is unsupported
Source

pub fn write_to_writer<W: Write>( &self, writer: W, format: RdfFormat, ) -> Result<()>

Write the graph to a writer in the specified format.

Uses Oxigraph’s Store API appropriately:

  • For graph formats (Turtle, N-Triples, RDF/XML): manually serializes default graph only
  • For dataset formats (TriG, N-Quads): uses dump_to_writer for all graphs
§Arguments
  • writer - Writer to write to
  • format - RDF format to use (Turtle, N-Triples, RDF/XML, TriG, N-Quads)
Source

pub fn write_to_string(&self, format: RdfFormat) -> Result<String>

Write the graph to a string in the specified format.

§Arguments
  • format - RDF format to use
§Returns

The serialized RDF as a string in the requested format.

Source

pub fn write_to_file_auto<P: AsRef<Path>>(&self, path: P) -> Result<()>

Write the graph to a file, auto-detecting format from extension.

Supported extensions:

  • .ttl, .turtle - Turtle
  • .nt, .ntriples - N-Triples
  • .rdf, .xml - RDF/XML
  • .trig - TriG
  • .nq, .nquads - N-Quads
§Arguments
  • path - Path to the output file
§Errors

Returns an error if:

  • The file extension is unsupported
  • The file cannot be created or written

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for GraphExport<'a>

§

impl<'a> !UnwindSafe for GraphExport<'a>

§

impl<'a> Freeze for GraphExport<'a>

§

impl<'a> Send for GraphExport<'a>

§

impl<'a> Sync for GraphExport<'a>

§

impl<'a> Unpin for GraphExport<'a>

§

impl<'a> UnsafeUnpin for GraphExport<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> EvidenceKind for T

Source§

default fn kind_label(&self) -> &'static str

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more