1use iref::Iri;
2use rdf_types::{vocabulary::IriVocabularyMut, Interpretation, Vocabulary};
3
4use crate::{
5 GraphVisitor, LinkedData, LinkedDataGraph, LinkedDataPredicateObjects, LinkedDataResource,
6 LinkedDataSubject, PredicateObjectsVisitor, ResourceInterpretation, SubjectVisitor, Visitor,
7};
8
9pub struct AnonymousBinding<'a, T>(pub &'a Iri, pub &'a T);
10
11impl<'a, T> AnonymousBinding<'a, T> {
12 pub fn new(iri: &'a Iri, value: &'a T) -> Self {
13 Self(iri, value)
14 }
15}
16
17impl<'a, I: Interpretation, V: Vocabulary, T> LinkedDataResource<I, V> for AnonymousBinding<'a, T> {
18 fn interpretation(
19 &self,
20 _vocabulary: &mut V,
21 _interpretation: &mut I,
22 ) -> ResourceInterpretation<I, V> {
23 ResourceInterpretation::Uninterpreted(None)
24 }
25}
26
27impl<
28 'a,
29 V: Vocabulary + IriVocabularyMut,
30 I: Interpretation,
31 T: LinkedDataPredicateObjects<I, V>,
32 > LinkedDataSubject<I, V> for AnonymousBinding<'a, T>
33{
34 fn visit_subject<S>(&self, mut serializer: S) -> Result<S::Ok, S::Error>
35 where
36 S: SubjectVisitor<I, V>,
37 {
38 serializer.predicate(self.0, self.1)?;
39 serializer.end()
40 }
41}
42
43impl<
44 'a,
45 V: Vocabulary + IriVocabularyMut,
46 I: Interpretation,
47 T: LinkedDataPredicateObjects<I, V>,
48 > LinkedDataPredicateObjects<I, V> for AnonymousBinding<'a, T>
49{
50 fn visit_objects<S>(&self, mut serializer: S) -> Result<S::Ok, S::Error>
51 where
52 S: PredicateObjectsVisitor<I, V>,
53 {
54 serializer.object(self)?;
55 serializer.end()
56 }
57}
58
59impl<
60 'a,
61 V: Vocabulary + IriVocabularyMut,
62 I: Interpretation,
63 T: LinkedDataPredicateObjects<I, V>,
64 > LinkedDataGraph<I, V> for AnonymousBinding<'a, T>
65{
66 fn visit_graph<S>(&self, mut serializer: S) -> Result<S::Ok, S::Error>
67 where
68 S: GraphVisitor<I, V>,
69 {
70 serializer.subject(self)?;
71 serializer.end()
72 }
73}
74
75impl<
76 'a,
77 V: Vocabulary + IriVocabularyMut,
78 I: Interpretation,
79 T: LinkedDataPredicateObjects<I, V>,
80 > LinkedData<I, V> for AnonymousBinding<'a, T>
81{
82 fn visit<S>(&self, mut serializer: S) -> Result<S::Ok, S::Error>
83 where
84 S: Visitor<I, V>,
85 {
86 serializer.default_graph(self)?;
87 serializer.end()
88 }
89}