linked_data_next/
anonymous.rs

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<I: Interpretation, V: Vocabulary, T> LinkedDataResource<I, V> for AnonymousBinding<'_, 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<V: Vocabulary + IriVocabularyMut, I: Interpretation, T: LinkedDataPredicateObjects<I, V>>
28	LinkedDataSubject<I, V> for AnonymousBinding<'_, T>
29{
30	fn visit_subject<S>(&self, mut serializer: S) -> Result<S::Ok, S::Error>
31	where
32		S: SubjectVisitor<I, V>,
33	{
34		serializer.predicate(self.0, self.1)?;
35		serializer.end()
36	}
37}
38
39impl<V: Vocabulary + IriVocabularyMut, I: Interpretation, T: LinkedDataPredicateObjects<I, V>>
40	LinkedDataPredicateObjects<I, V> for AnonymousBinding<'_, T>
41{
42	fn visit_objects<S>(&self, mut serializer: S) -> Result<S::Ok, S::Error>
43	where
44		S: PredicateObjectsVisitor<I, V>,
45	{
46		serializer.object(self)?;
47		serializer.end()
48	}
49}
50
51impl<V: Vocabulary + IriVocabularyMut, I: Interpretation, T: LinkedDataPredicateObjects<I, V>>
52	LinkedDataGraph<I, V> for AnonymousBinding<'_, T>
53{
54	fn visit_graph<S>(&self, mut serializer: S) -> Result<S::Ok, S::Error>
55	where
56		S: GraphVisitor<I, V>,
57	{
58		serializer.subject(self)?;
59		serializer.end()
60	}
61}
62
63impl<V: Vocabulary + IriVocabularyMut, I: Interpretation, T: LinkedDataPredicateObjects<I, V>>
64	LinkedData<I, V> for AnonymousBinding<'_, T>
65{
66	fn visit<S>(&self, mut serializer: S) -> Result<S::Ok, S::Error>
67	where
68		S: Visitor<I, V>,
69	{
70		serializer.default_graph(self)?;
71		serializer.end()
72	}
73}