1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use iref::Iri;
use rdf_types::{vocabulary::IriVocabularyMut, Interpretation, Vocabulary};

use crate::{
	GraphVisitor, LinkedData, LinkedDataGraph, LinkedDataPredicateObjects, LinkedDataResource,
	LinkedDataSubject, PredicateObjectsVisitor, ResourceInterpretation, SubjectVisitor, Visitor,
};

pub struct AnonymousBinding<'a, T>(pub &'a Iri, pub &'a T);

impl<'a, T> AnonymousBinding<'a, T> {
	pub fn new(iri: &'a Iri, value: &'a T) -> Self {
		Self(iri, value)
	}
}

impl<'a, I: Interpretation, V: Vocabulary, T> LinkedDataResource<I, V> for AnonymousBinding<'a, T> {
	fn interpretation(
		&self,
		_vocabulary: &mut V,
		_interpretation: &mut I,
	) -> ResourceInterpretation<I, V> {
		ResourceInterpretation::Uninterpreted(None)
	}
}

impl<
		'a,
		V: Vocabulary + IriVocabularyMut,
		I: Interpretation,
		T: LinkedDataPredicateObjects<I, V>,
	> LinkedDataSubject<I, V> for AnonymousBinding<'a, T>
{
	fn visit_subject<S>(&self, mut serializer: S) -> Result<S::Ok, S::Error>
	where
		S: SubjectVisitor<I, V>,
	{
		serializer.predicate(self.0, self.1)?;
		serializer.end()
	}
}

impl<
		'a,
		V: Vocabulary + IriVocabularyMut,
		I: Interpretation,
		T: LinkedDataPredicateObjects<I, V>,
	> LinkedDataPredicateObjects<I, V> for AnonymousBinding<'a, T>
{
	fn visit_objects<S>(&self, mut serializer: S) -> Result<S::Ok, S::Error>
	where
		S: PredicateObjectsVisitor<I, V>,
	{
		serializer.object(self)?;
		serializer.end()
	}
}

impl<
		'a,
		V: Vocabulary + IriVocabularyMut,
		I: Interpretation,
		T: LinkedDataPredicateObjects<I, V>,
	> LinkedDataGraph<I, V> for AnonymousBinding<'a, T>
{
	fn visit_graph<S>(&self, mut serializer: S) -> Result<S::Ok, S::Error>
	where
		S: GraphVisitor<I, V>,
	{
		serializer.subject(self)?;
		serializer.end()
	}
}

impl<
		'a,
		V: Vocabulary + IriVocabularyMut,
		I: Interpretation,
		T: LinkedDataPredicateObjects<I, V>,
	> LinkedData<I, V> for AnonymousBinding<'a, T>
{
	fn visit<S>(&self, mut serializer: S) -> Result<S::Ok, S::Error>
	where
		S: Visitor<I, V>,
	{
		serializer.default_graph(self)?;
		serializer.end()
	}
}