|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
/// A file serialization format.
|
|
|
|
|
///
|
|
|
|
|
/// Is implemented by `GraphSyntax` for graph files and `DatasetSyntax` for dataset files.
|
|
|
|
|
/// Is implemented by `GraphFormat` for graph files and `DatasetFormat` for dataset files.
|
|
|
|
|
#[deprecated(note = "Use directly the methods on the implementing types")] |
|
|
|
|
pub trait FileSyntax: Sized { |
|
|
|
|
/// Its canonical IRI according to the [Unique URIs for file formats registry](https://www.w3.org/ns/formats/).
|
|
|
|
@ -12,16 +12,16 @@ pub trait FileSyntax: Sized { |
|
|
|
|
/// Its [IANA-registered](https://tools.ietf.org/html/rfc2046) file extension.
|
|
|
|
|
fn file_extension(self) -> &'static str; |
|
|
|
|
|
|
|
|
|
/// Looks for a known syntax from a media type.
|
|
|
|
|
/// Looks for a known format from a media type.
|
|
|
|
|
fn from_mime_type(media_type: &str) -> Option<Self>; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// [RDF graph](https://www.w3.org/TR/rdf11-concepts/#dfn-graph) serialization formats.
|
|
|
|
|
///
|
|
|
|
|
/// This enumeration is non exhaustive. New syntaxes like JSON-LD will be added in the future.
|
|
|
|
|
/// This enumeration is non exhaustive. New formats like JSON-LD will be added in the future.
|
|
|
|
|
#[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)] |
|
|
|
|
#[non_exhaustive] |
|
|
|
|
pub enum GraphSyntax { |
|
|
|
|
pub enum GraphFormat { |
|
|
|
|
/// [N-Triples](https://www.w3.org/TR/n-triples/)
|
|
|
|
|
NTriples, |
|
|
|
|
/// [Turtle](https://www.w3.org/TR/turtle/)
|
|
|
|
@ -30,70 +30,70 @@ pub enum GraphSyntax { |
|
|
|
|
RdfXml, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl GraphSyntax { |
|
|
|
|
/// The syntax canonical IRI according to the [Unique URIs for file formats registry](https://www.w3.org/ns/formats/).
|
|
|
|
|
impl GraphFormat { |
|
|
|
|
/// The format canonical IRI according to the [Unique URIs for file formats registry](https://www.w3.org/ns/formats/).
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// use oxigraph::io::GraphSyntax;
|
|
|
|
|
/// use oxigraph::io::GraphFormat;
|
|
|
|
|
///
|
|
|
|
|
/// assert_eq!(GraphSyntax::NTriples.iri(), "http://www.w3.org/ns/formats/N-Triples")
|
|
|
|
|
/// assert_eq!(GraphFormat::NTriples.iri(), "http://www.w3.org/ns/formats/N-Triples")
|
|
|
|
|
/// ```
|
|
|
|
|
pub fn iri(self) -> &'static str { |
|
|
|
|
match self { |
|
|
|
|
GraphSyntax::NTriples => "http://www.w3.org/ns/formats/N-Triples", |
|
|
|
|
GraphSyntax::Turtle => "http://www.w3.org/ns/formats/Turtle", |
|
|
|
|
GraphSyntax::RdfXml => "http://www.w3.org/ns/formats/RDF_XML", |
|
|
|
|
GraphFormat::NTriples => "http://www.w3.org/ns/formats/N-Triples", |
|
|
|
|
GraphFormat::Turtle => "http://www.w3.org/ns/formats/Turtle", |
|
|
|
|
GraphFormat::RdfXml => "http://www.w3.org/ns/formats/RDF_XML", |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// The syntax [IANA media type](https://tools.ietf.org/html/rfc2046).
|
|
|
|
|
/// The format [IANA media type](https://tools.ietf.org/html/rfc2046).
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// use oxigraph::io::GraphSyntax;
|
|
|
|
|
/// use oxigraph::io::GraphFormat;
|
|
|
|
|
///
|
|
|
|
|
/// assert_eq!(GraphSyntax::NTriples.media_type(), "application/n-triples")
|
|
|
|
|
/// assert_eq!(GraphFormat::NTriples.media_type(), "application/n-triples")
|
|
|
|
|
/// ```
|
|
|
|
|
pub fn media_type(self) -> &'static str { |
|
|
|
|
match self { |
|
|
|
|
GraphSyntax::NTriples => "application/n-triples", |
|
|
|
|
GraphSyntax::Turtle => "text/turtle", |
|
|
|
|
GraphSyntax::RdfXml => "application/rdf+xml", |
|
|
|
|
GraphFormat::NTriples => "application/n-triples", |
|
|
|
|
GraphFormat::Turtle => "text/turtle", |
|
|
|
|
GraphFormat::RdfXml => "application/rdf+xml", |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// The syntax [IANA-registered](https://tools.ietf.org/html/rfc2046) file extension.
|
|
|
|
|
/// The format [IANA-registered](https://tools.ietf.org/html/rfc2046) file extension.
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// use oxigraph::io::GraphSyntax;
|
|
|
|
|
/// use oxigraph::io::GraphFormat;
|
|
|
|
|
///
|
|
|
|
|
/// assert_eq!(GraphSyntax::NTriples.file_extension(), "nt")
|
|
|
|
|
/// assert_eq!(GraphFormat::NTriples.file_extension(), "nt")
|
|
|
|
|
/// ```
|
|
|
|
|
pub fn file_extension(self) -> &'static str { |
|
|
|
|
match self { |
|
|
|
|
GraphSyntax::NTriples => "nt", |
|
|
|
|
GraphSyntax::Turtle => "ttl", |
|
|
|
|
GraphSyntax::RdfXml => "rdf", |
|
|
|
|
GraphFormat::NTriples => "nt", |
|
|
|
|
GraphFormat::Turtle => "ttl", |
|
|
|
|
GraphFormat::RdfXml => "rdf", |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/// Looks for a known syntax from a media type.
|
|
|
|
|
/// Looks for a known format from a media type.
|
|
|
|
|
///
|
|
|
|
|
/// It supports some media type aliases.
|
|
|
|
|
/// For example "application/xml" is going to return `GraphSyntax::RdfXml` even if it is not its canonical media type.
|
|
|
|
|
/// For example "application/xml" is going to return `GraphFormat::RdfXml` even if it is not its canonical media type.
|
|
|
|
|
///
|
|
|
|
|
/// Example:
|
|
|
|
|
/// ```
|
|
|
|
|
/// use oxigraph::io::GraphSyntax;
|
|
|
|
|
/// use oxigraph::io::GraphFormat;
|
|
|
|
|
///
|
|
|
|
|
/// assert_eq!(GraphSyntax::from_media_type("text/turtle; charset=utf-8"), Some(GraphSyntax::Turtle))
|
|
|
|
|
/// assert_eq!(GraphFormat::from_media_type("text/turtle; charset=utf-8"), Some(GraphFormat::Turtle))
|
|
|
|
|
/// ```
|
|
|
|
|
pub fn from_media_type(media_type: &str) -> Option<Self> { |
|
|
|
|
if let Some(base_type) = media_type.split(';').next() { |
|
|
|
|
match base_type.trim() { |
|
|
|
|
"application/n-triples" | "text/plain" => Some(GraphSyntax::NTriples), |
|
|
|
|
"application/n-triples" | "text/plain" => Some(GraphFormat::NTriples), |
|
|
|
|
"text/turtle" | "application/turtle" | "application/x-turtle" => { |
|
|
|
|
Some(GraphSyntax::Turtle) |
|
|
|
|
Some(GraphFormat::Turtle) |
|
|
|
|
} |
|
|
|
|
"application/rdf+xml" | "application/xml" | "text/xml" => Some(GraphSyntax::RdfXml), |
|
|
|
|
"application/rdf+xml" | "application/xml" | "text/xml" => Some(GraphFormat::RdfXml), |
|
|
|
|
_ => None, |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
@ -103,7 +103,7 @@ impl GraphSyntax { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[allow(deprecated)] |
|
|
|
|
impl FileSyntax for GraphSyntax { |
|
|
|
|
impl FileSyntax for GraphFormat { |
|
|
|
|
fn iri(self) -> &'static str { |
|
|
|
|
self.iri() |
|
|
|
|
} |
|
|
|
@ -123,75 +123,75 @@ impl FileSyntax for GraphSyntax { |
|
|
|
|
|
|
|
|
|
/// [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset) serialization formats.
|
|
|
|
|
///
|
|
|
|
|
/// This enumeration is non exhaustive. New syntaxes like JSON-LD will be added in the future.
|
|
|
|
|
/// This enumeration is non exhaustive. New formats like JSON-LD will be added in the future.
|
|
|
|
|
#[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)] |
|
|
|
|
#[non_exhaustive] |
|
|
|
|
pub enum DatasetSyntax { |
|
|
|
|
pub enum DatasetFormat { |
|
|
|
|
/// [N-Quads](https://www.w3.org/TR/n-quads/)
|
|
|
|
|
NQuads, |
|
|
|
|
/// [TriG](https://www.w3.org/TR/trig/)
|
|
|
|
|
TriG, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl DatasetSyntax { |
|
|
|
|
/// The syntax canonical IRI according to the [Unique URIs for file formats registry](https://www.w3.org/ns/formats/).
|
|
|
|
|
impl DatasetFormat { |
|
|
|
|
/// The format canonical IRI according to the [Unique URIs for file formats registry](https://www.w3.org/ns/formats/).
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// use oxigraph::io::DatasetSyntax;
|
|
|
|
|
/// use oxigraph::io::DatasetFormat;
|
|
|
|
|
///
|
|
|
|
|
/// assert_eq!(DatasetSyntax::NQuads.iri(), "http://www.w3.org/ns/formats/N-Quads")
|
|
|
|
|
/// assert_eq!(DatasetFormat::NQuads.iri(), "http://www.w3.org/ns/formats/N-Quads")
|
|
|
|
|
/// ```
|
|
|
|
|
pub fn iri(self) -> &'static str { |
|
|
|
|
match self { |
|
|
|
|
DatasetSyntax::NQuads => "http://www.w3.org/ns/formats/N-Quads", |
|
|
|
|
DatasetSyntax::TriG => "http://www.w3.org/ns/formats/TriG", |
|
|
|
|
DatasetFormat::NQuads => "http://www.w3.org/ns/formats/N-Quads", |
|
|
|
|
DatasetFormat::TriG => "http://www.w3.org/ns/formats/TriG", |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// The syntax [IANA media type](https://tools.ietf.org/html/rfc2046).
|
|
|
|
|
/// The format [IANA media type](https://tools.ietf.org/html/rfc2046).
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// use oxigraph::io::DatasetSyntax;
|
|
|
|
|
/// use oxigraph::io::DatasetFormat;
|
|
|
|
|
///
|
|
|
|
|
/// assert_eq!(DatasetSyntax::NQuads.media_type(), "application/n-quads")
|
|
|
|
|
/// assert_eq!(DatasetFormat::NQuads.media_type(), "application/n-quads")
|
|
|
|
|
/// ```
|
|
|
|
|
pub fn media_type(self) -> &'static str { |
|
|
|
|
match self { |
|
|
|
|
DatasetSyntax::NQuads => "application/n-quads", |
|
|
|
|
DatasetSyntax::TriG => "application/trig", |
|
|
|
|
DatasetFormat::NQuads => "application/n-quads", |
|
|
|
|
DatasetFormat::TriG => "application/trig", |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// The syntax [IANA-registered](https://tools.ietf.org/html/rfc2046) file extension.
|
|
|
|
|
/// The format [IANA-registered](https://tools.ietf.org/html/rfc2046) file extension.
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// use oxigraph::io::DatasetSyntax;
|
|
|
|
|
/// use oxigraph::io::DatasetFormat;
|
|
|
|
|
///
|
|
|
|
|
/// assert_eq!(DatasetSyntax::NQuads.file_extension(), "nq")
|
|
|
|
|
/// assert_eq!(DatasetFormat::NQuads.file_extension(), "nq")
|
|
|
|
|
/// ```
|
|
|
|
|
pub fn file_extension(self) -> &'static str { |
|
|
|
|
match self { |
|
|
|
|
DatasetSyntax::NQuads => "nq", |
|
|
|
|
DatasetSyntax::TriG => "trig", |
|
|
|
|
DatasetFormat::NQuads => "nq", |
|
|
|
|
DatasetFormat::TriG => "trig", |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/// Looks for a known syntax from a media type.
|
|
|
|
|
/// Looks for a known format from a media type.
|
|
|
|
|
///
|
|
|
|
|
/// It supports some media type aliases.
|
|
|
|
|
///
|
|
|
|
|
/// Example:
|
|
|
|
|
/// ```
|
|
|
|
|
/// use oxigraph::io::DatasetSyntax;
|
|
|
|
|
/// use oxigraph::io::DatasetFormat;
|
|
|
|
|
///
|
|
|
|
|
/// assert_eq!(DatasetSyntax::from_media_type("application/n-quads; charset=utf-8"), Some(DatasetSyntax::NQuads))
|
|
|
|
|
/// assert_eq!(DatasetFormat::from_media_type("application/n-quads; charset=utf-8"), Some(DatasetFormat::NQuads))
|
|
|
|
|
/// ```
|
|
|
|
|
pub fn from_media_type(media_type: &str) -> Option<Self> { |
|
|
|
|
if let Some(base_type) = media_type.split(';').next() { |
|
|
|
|
match base_type.trim() { |
|
|
|
|
"application/n-quads" | "text/x-nquads" | "text/nquads" => { |
|
|
|
|
Some(DatasetSyntax::NQuads) |
|
|
|
|
Some(DatasetFormat::NQuads) |
|
|
|
|
} |
|
|
|
|
"application/trig" | "application/x-trig" => Some(DatasetSyntax::TriG), |
|
|
|
|
"application/trig" | "application/x-trig" => Some(DatasetFormat::TriG), |
|
|
|
|
_ => None, |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
@ -201,7 +201,7 @@ impl DatasetSyntax { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[allow(deprecated)] |
|
|
|
|
impl FileSyntax for DatasetSyntax { |
|
|
|
|
impl FileSyntax for DatasetFormat { |
|
|
|
|
fn iri(self) -> &'static str { |
|
|
|
|
self.iri() |
|
|
|
|
} |