|
|
@ -1,8 +1,9 @@ |
|
|
|
/// A file serialization format.
|
|
|
|
/// A file serialization format.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// Is implemented by `GraphSyntax` for graph files and `DatasetSyntax` for dataset files.
|
|
|
|
/// Is implemented by `GraphSyntax` for graph files and `DatasetSyntax` for dataset files.
|
|
|
|
|
|
|
|
#[deprecated(note = "Use directly the methods on the implementing types")] |
|
|
|
pub trait FileSyntax: Sized { |
|
|
|
pub trait FileSyntax: Sized { |
|
|
|
/// Its canonical IRI according to [Unique URIs for file formats registry](https://www.w3.org/ns/formats/).
|
|
|
|
/// Its canonical IRI according to the [Unique URIs for file formats registry](https://www.w3.org/ns/formats/).
|
|
|
|
fn iri(self) -> &'static str; |
|
|
|
fn iri(self) -> &'static str; |
|
|
|
|
|
|
|
|
|
|
|
/// Its [IANA media type](https://tools.ietf.org/html/rfc2046).
|
|
|
|
/// Its [IANA media type](https://tools.ietf.org/html/rfc2046).
|
|
|
@ -12,12 +13,6 @@ pub trait FileSyntax: Sized { |
|
|
|
fn file_extension(self) -> &'static str; |
|
|
|
fn file_extension(self) -> &'static str; |
|
|
|
|
|
|
|
|
|
|
|
/// Looks for a known syntax from a media type.
|
|
|
|
/// Looks for a known syntax from a media type.
|
|
|
|
///
|
|
|
|
|
|
|
|
/// Example:
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
/// use oxigraph::{GraphSyntax, FileSyntax};
|
|
|
|
|
|
|
|
/// assert_eq!(GraphSyntax::from_mime_type("text/turtle; charset=utf-8"), Some(GraphSyntax::Turtle))
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
fn from_mime_type(media_type: &str) -> Option<Self>; |
|
|
|
fn from_mime_type(media_type: &str) -> Option<Self>; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -32,8 +27,15 @@ pub enum GraphSyntax { |
|
|
|
RdfXml, |
|
|
|
RdfXml, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl FileSyntax for GraphSyntax { |
|
|
|
impl GraphSyntax { |
|
|
|
fn iri(self) -> &'static str { |
|
|
|
/// The syntax canonical IRI according to the [Unique URIs for file formats registry](https://www.w3.org/ns/formats/).
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
/// use oxigraph::io::GraphSyntax;
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// assert_eq!(GraphSyntax::NTriples.iri(), "http://www.w3.org/ns/formats/N-Triples")
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
pub fn iri(self) -> &'static str { |
|
|
|
match self { |
|
|
|
match self { |
|
|
|
GraphSyntax::NTriples => "http://www.w3.org/ns/formats/N-Triples", |
|
|
|
GraphSyntax::NTriples => "http://www.w3.org/ns/formats/N-Triples", |
|
|
|
GraphSyntax::Turtle => "http://www.w3.org/ns/formats/Turtle", |
|
|
|
GraphSyntax::Turtle => "http://www.w3.org/ns/formats/Turtle", |
|
|
@ -41,7 +43,14 @@ impl FileSyntax for GraphSyntax { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn media_type(self) -> &'static str { |
|
|
|
/// The syntax [IANA media type](https://tools.ietf.org/html/rfc2046).
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
/// use oxigraph::io::GraphSyntax;
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// assert_eq!(GraphSyntax::NTriples.media_type(), "application/n-triples")
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
pub fn media_type(self) -> &'static str { |
|
|
|
match self { |
|
|
|
match self { |
|
|
|
GraphSyntax::NTriples => "application/n-triples", |
|
|
|
GraphSyntax::NTriples => "application/n-triples", |
|
|
|
GraphSyntax::Turtle => "text/turtle", |
|
|
|
GraphSyntax::Turtle => "text/turtle", |
|
|
@ -49,17 +58,34 @@ impl FileSyntax for GraphSyntax { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn file_extension(self) -> &'static str { |
|
|
|
/// The syntax [IANA-registered](https://tools.ietf.org/html/rfc2046) file extension.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
/// use oxigraph::io::GraphSyntax;
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// assert_eq!(GraphSyntax::NTriples.file_extension(), "nt")
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
pub fn file_extension(self) -> &'static str { |
|
|
|
match self { |
|
|
|
match self { |
|
|
|
GraphSyntax::NTriples => "nt", |
|
|
|
GraphSyntax::NTriples => "nt", |
|
|
|
GraphSyntax::Turtle => "ttl", |
|
|
|
GraphSyntax::Turtle => "ttl", |
|
|
|
GraphSyntax::RdfXml => "rdf", |
|
|
|
GraphSyntax::RdfXml => "rdf", |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// Looks for a known syntax from a media type.
|
|
|
|
fn from_mime_type(media_type: &str) -> Option<Self> { |
|
|
|
///
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// Example:
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
/// use oxigraph::io::GraphSyntax;
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// assert_eq!(GraphSyntax::from_media_type("text/turtle; charset=utf-8"), Some(GraphSyntax::Turtle))
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
pub fn from_media_type(media_type: &str) -> Option<Self> { |
|
|
|
if let Some(base_type) = media_type.split(';').next() { |
|
|
|
if let Some(base_type) = media_type.split(';').next() { |
|
|
|
match base_type { |
|
|
|
match base_type.trim() { |
|
|
|
"application/n-triples" | "text/plain" => Some(GraphSyntax::NTriples), |
|
|
|
"application/n-triples" | "text/plain" => Some(GraphSyntax::NTriples), |
|
|
|
"text/turtle" | "application/turtle" | "application/x-turtle" => { |
|
|
|
"text/turtle" | "application/turtle" | "application/x-turtle" => { |
|
|
|
Some(GraphSyntax::Turtle) |
|
|
|
Some(GraphSyntax::Turtle) |
|
|
@ -73,6 +99,25 @@ impl FileSyntax for GraphSyntax { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[allow(deprecated)] |
|
|
|
|
|
|
|
impl FileSyntax for GraphSyntax { |
|
|
|
|
|
|
|
fn iri(self) -> &'static str { |
|
|
|
|
|
|
|
self.iri() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn media_type(self) -> &'static str { |
|
|
|
|
|
|
|
self.media_type() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn file_extension(self) -> &'static str { |
|
|
|
|
|
|
|
self.file_extension() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn from_mime_type(media_type: &str) -> Option<Self> { |
|
|
|
|
|
|
|
Self::from_media_type(media_type) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset) serialization formats.
|
|
|
|
/// [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset) serialization formats.
|
|
|
|
#[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)] |
|
|
|
#[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)] |
|
|
|
pub enum DatasetSyntax { |
|
|
|
pub enum DatasetSyntax { |
|
|
@ -82,31 +127,61 @@ pub enum DatasetSyntax { |
|
|
|
TriG, |
|
|
|
TriG, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl FileSyntax for DatasetSyntax { |
|
|
|
impl DatasetSyntax { |
|
|
|
fn iri(self) -> &'static str { |
|
|
|
/// The syntax canonical IRI according to the [Unique URIs for file formats registry](https://www.w3.org/ns/formats/).
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
/// use oxigraph::io::DatasetSyntax;
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// assert_eq!(DatasetSyntax::NQuads.iri(), "http://www.w3.org/ns/formats/N-Quads")
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
pub fn iri(self) -> &'static str { |
|
|
|
match self { |
|
|
|
match self { |
|
|
|
DatasetSyntax::NQuads => "http://www.w3.org/ns/formats/N-Quads", |
|
|
|
DatasetSyntax::NQuads => "http://www.w3.org/ns/formats/N-Quads", |
|
|
|
DatasetSyntax::TriG => "http://www.w3.org/ns/formats/TriG", |
|
|
|
DatasetSyntax::TriG => "http://www.w3.org/ns/formats/TriG", |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn media_type(self) -> &'static str { |
|
|
|
/// The syntax [IANA media type](https://tools.ietf.org/html/rfc2046).
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
/// use oxigraph::io::DatasetSyntax;
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// assert_eq!(DatasetSyntax::NQuads.media_type(), "application/n-quads")
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
pub fn media_type(self) -> &'static str { |
|
|
|
match self { |
|
|
|
match self { |
|
|
|
DatasetSyntax::NQuads => "application/n-quads", |
|
|
|
DatasetSyntax::NQuads => "application/n-quads", |
|
|
|
DatasetSyntax::TriG => "application/trig", |
|
|
|
DatasetSyntax::TriG => "application/trig", |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn file_extension(self) -> &'static str { |
|
|
|
/// The syntax [IANA-registered](https://tools.ietf.org/html/rfc2046) file extension.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
/// use oxigraph::io::DatasetSyntax;
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// assert_eq!(DatasetSyntax::NQuads.file_extension(), "nq")
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
pub fn file_extension(self) -> &'static str { |
|
|
|
match self { |
|
|
|
match self { |
|
|
|
DatasetSyntax::NQuads => "nq", |
|
|
|
DatasetSyntax::NQuads => "nq", |
|
|
|
DatasetSyntax::TriG => "trig", |
|
|
|
DatasetSyntax::TriG => "trig", |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// Looks for a known syntax from a media type.
|
|
|
|
fn from_mime_type(media_type: &str) -> Option<Self> { |
|
|
|
///
|
|
|
|
|
|
|
|
/// It supports some media type aliases.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// Example:
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
/// use oxigraph::io::DatasetSyntax;
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// assert_eq!(DatasetSyntax::from_media_type("application/n-quads; charset=utf-8"), Some(DatasetSyntax::NQuads))
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
pub fn from_media_type(media_type: &str) -> Option<Self> { |
|
|
|
if let Some(base_type) = media_type.split(';').next() { |
|
|
|
if let Some(base_type) = media_type.split(';').next() { |
|
|
|
match base_type { |
|
|
|
match base_type.trim() { |
|
|
|
"application/n-quads" | "text/x-nquads" | "text/nquads" => { |
|
|
|
"application/n-quads" | "text/x-nquads" | "text/nquads" => { |
|
|
|
Some(DatasetSyntax::NQuads) |
|
|
|
Some(DatasetSyntax::NQuads) |
|
|
|
} |
|
|
|
} |
|
|
@ -118,3 +193,22 @@ impl FileSyntax for DatasetSyntax { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[allow(deprecated)] |
|
|
|
|
|
|
|
impl FileSyntax for DatasetSyntax { |
|
|
|
|
|
|
|
fn iri(self) -> &'static str { |
|
|
|
|
|
|
|
self.iri() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn media_type(self) -> &'static str { |
|
|
|
|
|
|
|
self.media_type() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn file_extension(self) -> &'static str { |
|
|
|
|
|
|
|
self.file_extension() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn from_mime_type(media_type: &str) -> Option<Self> { |
|
|
|
|
|
|
|
Self::from_media_type(media_type) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |