rdf_types/interpretation/
blank_id.rs

1use crate::{
2	vocabulary::{BlankIdVocabulary, BlankIdVocabularyMut},
3	BlankId, BlankIdBuf, Interpretation,
4};
5
6/// Blank node identifier interpretation.
7pub trait BlankIdInterpretation<B: ?Sized>: Interpretation {
8	/// Returns the interpretation of the given blank node identifier, if any.
9	fn blank_id_interpretation(&self, blank_id: &B) -> Option<Self::Resource>;
10
11	fn lexical_blank_id_interpretation(
12		&self,
13		vocabulary: &impl BlankIdVocabulary<BlankId = B>,
14		blank_id: &BlankId,
15	) -> Option<Self::Resource>
16	where
17		B: Sized,
18	{
19		vocabulary
20			.get_blank_id(blank_id)
21			.and_then(|blank_id| self.blank_id_interpretation(&blank_id))
22	}
23}
24
25impl<B, T: BlankIdInterpretation<B>> BlankIdInterpretation<B> for &T {
26	fn blank_id_interpretation(&self, blank_id: &B) -> Option<Self::Resource> {
27		T::blank_id_interpretation(*self, blank_id)
28	}
29
30	fn lexical_blank_id_interpretation(
31		&self,
32		vocabulary: &impl BlankIdVocabulary<BlankId = B>,
33		blank_id: &BlankId,
34	) -> Option<Self::Resource>
35	where
36		B: Sized,
37	{
38		T::lexical_blank_id_interpretation(*self, vocabulary, blank_id)
39	}
40}
41
42impl<B, T: BlankIdInterpretation<B>> BlankIdInterpretation<B> for &mut T {
43	fn blank_id_interpretation(&self, blank_id: &B) -> Option<Self::Resource> {
44		T::blank_id_interpretation(*self, blank_id)
45	}
46
47	fn lexical_blank_id_interpretation(
48		&self,
49		vocabulary: &impl BlankIdVocabulary<BlankId = B>,
50		blank_id: &BlankId,
51	) -> Option<Self::Resource>
52	where
53		B: Sized,
54	{
55		T::lexical_blank_id_interpretation(*self, vocabulary, blank_id)
56	}
57}
58
59/// Blank node identifier interpretation.
60pub trait BlankIdInterpretationMut<B = BlankIdBuf>: Interpretation {
61	/// Interprets the given blank node identifier.
62	fn interpret_blank_id(&mut self, blank_id: B) -> Self::Resource;
63
64	fn interpret_lexical_blank_id(
65		&mut self,
66		vocabulary: &mut impl BlankIdVocabularyMut<BlankId = B>,
67		blank_id: &BlankId,
68	) -> Self::Resource {
69		self.interpret_blank_id(vocabulary.insert_blank_id(blank_id))
70	}
71
72	fn interpret_owned_lexical_blank_id(
73		&mut self,
74		vocabulary: &mut impl BlankIdVocabularyMut<BlankId = B>,
75		blank_id: BlankIdBuf,
76	) -> Self::Resource {
77		self.interpret_blank_id(vocabulary.insert_owned_blank_id(blank_id))
78	}
79}
80
81impl<B, T: BlankIdInterpretationMut<B>> BlankIdInterpretationMut<B> for &mut T {
82	fn interpret_blank_id(&mut self, blank_id: B) -> Self::Resource {
83		T::interpret_blank_id(*self, blank_id)
84	}
85
86	fn interpret_lexical_blank_id(
87		&mut self,
88		vocabulary: &mut impl BlankIdVocabularyMut<BlankId = B>,
89		blank_id: &BlankId,
90	) -> Self::Resource {
91		T::interpret_lexical_blank_id(*self, vocabulary, blank_id)
92	}
93
94	fn interpret_owned_lexical_blank_id(
95		&mut self,
96		vocabulary: &mut impl BlankIdVocabularyMut<BlankId = B>,
97		blank_id: BlankIdBuf,
98	) -> Self::Resource {
99		T::interpret_owned_lexical_blank_id(*self, vocabulary, blank_id)
100	}
101}
102
103pub trait ReverseBlankIdInterpretation: Interpretation {
104	type BlankId;
105	type BlankIds<'a>: Clone + Iterator<Item = &'a Self::BlankId>
106	where
107		Self: 'a;
108
109	fn blank_ids_of<'a>(&'a self, id: &'a Self::Resource) -> Self::BlankIds<'a>;
110}
111
112impl<T: ReverseBlankIdInterpretation> ReverseBlankIdInterpretation for &T {
113	type BlankId = T::BlankId;
114	type BlankIds<'a>
115		= T::BlankIds<'a>
116	where
117		Self: 'a;
118
119	fn blank_ids_of<'a>(&'a self, id: &'a Self::Resource) -> Self::BlankIds<'a> {
120		T::blank_ids_of(*self, id)
121	}
122}
123
124impl<T: ReverseBlankIdInterpretation> ReverseBlankIdInterpretation for &mut T {
125	type BlankId = T::BlankId;
126	type BlankIds<'a>
127		= T::BlankIds<'a>
128	where
129		Self: 'a;
130
131	fn blank_ids_of<'a>(&'a self, id: &'a Self::Resource) -> Self::BlankIds<'a> {
132		T::blank_ids_of(*self, id)
133	}
134}
135
136pub trait ReverseBlankIdInterpretationMut: ReverseBlankIdInterpretation {
137	fn assign_blank_id(&mut self, id: &Self::Resource, blank_id: Self::BlankId) -> bool;
138}
139
140impl<T: ReverseBlankIdInterpretationMut> ReverseBlankIdInterpretationMut for &mut T {
141	fn assign_blank_id(&mut self, id: &Self::Resource, blank_id: Self::BlankId) -> bool {
142		T::assign_blank_id(*self, id, blank_id)
143	}
144}