linked_data_next/datatypes/
ser.rs1use rdf_types::{
2 vocabulary::{IriVocabularyMut, LiteralVocabularyMut},
3 Id, Interpretation, Term, Vocabulary,
4};
5
6use crate::{
7 CowRdfTerm, LinkedDataPredicateObjects, LinkedDataResource, LinkedDataSubject,
8 PredicateObjectsVisitor, RdfLiteral, RdfLiteralRef, ResourceInterpretation,
9};
10
11macro_rules! datatype {
12 ($($ty:ty : $variant:ident),*) => {
13 $(
14 impl<V: Vocabulary + IriVocabularyMut + LiteralVocabularyMut, I: Interpretation> LinkedDataResource<I, V> for $ty {
15 fn interpretation(
16 &self,
17 _vocabulary: &mut V,
18 _interpretation: &mut I,
19 ) -> ResourceInterpretation<I, V> {
20 ResourceInterpretation::Uninterpreted(Some(CowRdfTerm::Owned(Term::Literal(RdfLiteral::Xsd(
21 xsd_types::Value::$variant(self.clone())
22 )))))
23 }
24 }
25
26 impl<V: Vocabulary + IriVocabularyMut + LiteralVocabularyMut, I: Interpretation> LinkedDataSubject<I, V> for $ty {
27 fn visit_subject<S>(&self, visitor: S) -> Result<S::Ok, S::Error>
28 where
29 S: crate::SubjectVisitor<I, V>
30 {
31 visitor.end()
32 }
33 }
34
35 impl<V: Vocabulary + IriVocabularyMut + LiteralVocabularyMut, I: Interpretation> LinkedDataPredicateObjects<I, V> for $ty {
36 fn visit_objects<S>(&self, mut visitor: S) -> Result<S::Ok, S::Error>
37 where
38 S: PredicateObjectsVisitor<I, V>,
39 {
40 visitor.object(self)?;
41 visitor.end()
42 }
43 }
44 )*
45 };
46}
47
48macro_rules! unsized_datatype {
49 ($($ty:ty : $variant:ident),*) => {
50 $(
51 impl<V: Vocabulary + IriVocabularyMut + LiteralVocabularyMut, I: Interpretation> LinkedDataResource<I, V> for $ty {
52 fn interpretation(
53 &self,
54 _vocabulary: &mut V,
55 _interpretation: &mut I,
56 ) -> ResourceInterpretation<I, V> {
57 ResourceInterpretation::Uninterpreted(Some(CowRdfTerm::Borrowed(Term::Literal(RdfLiteralRef::Xsd(
58 xsd_types::ValueRef::$variant(self)
59 )))))
60 }
61 }
62
63 impl<V: Vocabulary + IriVocabularyMut + LiteralVocabularyMut, I: Interpretation> LinkedDataSubject<I, V> for $ty {
64 fn visit_subject<S>(&self, visitor: S) -> Result<S::Ok, S::Error>
65 where
66 S: crate::SubjectVisitor<I, V>
67 {
68 visitor.end()
69 }
70 }
71
72 impl<V: Vocabulary + IriVocabularyMut + LiteralVocabularyMut, I: Interpretation> LinkedDataPredicateObjects<I, V> for $ty {
73 fn visit_objects<S>(&self, mut visitor: S) -> Result<S::Ok, S::Error>
74 where
75 S: PredicateObjectsVisitor<I, V>,
76 {
77 visitor.object(self)?;
78 visitor.end()
79 }
80 }
81 )*
82 };
83}
84
85datatype! {
86 u8: UnsignedByte,
87 u16: UnsignedShort,
88 u32: UnsignedInt,
89 u64: UnsignedLong,
90 i8: Byte,
91 i16: Short,
92 i32: Int,
93 i64: Long,
94 String: String,
95 xsd_types::DateTime: DateTime
96}
97
98unsized_datatype! {
99 str: String
100}
101
102impl<V: Vocabulary + IriVocabularyMut + LiteralVocabularyMut, I: Interpretation>
103 LinkedDataResource<I, V> for xsd_types::AnyUriBuf
104{
105 fn interpretation(
106 &self,
107 _vocabulary: &mut V,
108 _interpretation: &mut I,
109 ) -> ResourceInterpretation<I, V> {
110 ResourceInterpretation::Uninterpreted(Some(CowRdfTerm::Owned(Term::Literal(
111 RdfLiteral::Xsd(xsd_types::Value::AnyUri(self.clone())),
112 ))))
113 }
114
115 fn reference_interpretation(
116 &self,
117 vocabulary: &mut V,
118 _interpretation: &mut I,
119 ) -> ResourceInterpretation<I, V> {
120 ResourceInterpretation::Uninterpreted(Some(CowRdfTerm::Owned(Term::Id(Id::Iri(
121 vocabulary.insert(self.as_iri()),
122 )))))
123 }
124}
125
126impl<V: Vocabulary + IriVocabularyMut + LiteralVocabularyMut, I: Interpretation>
127 LinkedDataSubject<I, V> for xsd_types::AnyUriBuf
128{
129 fn visit_subject<S>(&self, visitor: S) -> Result<S::Ok, S::Error>
130 where
131 S: crate::SubjectVisitor<I, V>,
132 {
133 visitor.end()
134 }
135}
136
137impl<V: Vocabulary + IriVocabularyMut + LiteralVocabularyMut, I: Interpretation>
138 LinkedDataPredicateObjects<I, V> for xsd_types::AnyUriBuf
139{
140 fn visit_objects<S>(&self, mut visitor: S) -> Result<S::Ok, S::Error>
141 where
142 S: PredicateObjectsVisitor<I, V>,
143 {
144 visitor.object(self)?;
145 visitor.end()
146 }
147}