1use rdf_types::Triple;
2
3mod view;
4
5pub use view::*;
6
7pub trait Graph {
12 type Subject;
13 type Predicate;
14 type Object;
15
16 type Triples<'a>: Iterator<
18 Item = Triple<&'a Self::Subject, &'a Self::Predicate, &'a Self::Object>,
19 > where
20 Self: 'a;
21
22 type Subjects<'a>: Iterator<Item = (&'a Self::Subject, Self::Predicates<'a>)>
26 where
27 Self: 'a;
28
29 type Predicates<'a>: Iterator<Item = (&'a Self::Predicate, Self::Objects<'a>)>
34 where
35 Self: 'a;
36
37 type Objects<'a>: Iterator<Item = &'a Self::Object>
41 where
42 Self: 'a;
43
44 type PatternMatching<'a, 'p>: Iterator<
45 Item = Triple<&'a Self::Subject, &'a Self::Predicate, &'a Self::Object>,
46 > where
47 Self: 'a,
48 Self::Subject: 'p,
49 Self::Predicate: 'p,
50 Self::Object: 'p;
51
52 fn len(&self) -> usize;
54
55 fn is_empty(&self) -> bool {
57 self.len() == 0
58 }
59
60 fn triples(&self) -> Self::Triples<'_>;
62
63 fn subjects(&self) -> Self::Subjects<'_>;
65
66 fn predicates(&self, subject: &Self::Subject) -> Self::Predicates<'_>;
68
69 fn objects(&self, subject: &Self::Subject, predicate: &Self::Predicate) -> Self::Objects<'_>;
72
73 fn contains(&self, triple: Triple<&Self::Subject, &Self::Predicate, &Self::Object>) -> bool;
75
76 #[allow(clippy::type_complexity)]
78 fn pattern_matching<'p>(
79 &self,
80 pattern: Triple<
81 Option<&'p Self::Subject>,
82 Option<&'p Self::Predicate>,
83 Option<&'p Self::Object>,
84 >,
85 ) -> Self::PatternMatching<'_, 'p>;
86
87 #[allow(clippy::type_complexity)]
89 fn any_match(
90 &self,
91 pattern: Triple<Option<&Self::Subject>, Option<&Self::Predicate>, Option<&Self::Object>>,
92 ) -> Option<Triple<&Self::Subject, &Self::Predicate, &Self::Object>> {
93 self.pattern_matching(pattern).next()
94 }
95
96 fn view<'a, A>(&'a self, subject: &'a Self::Subject, access: A) -> GraphView<Self, A> {
99 GraphView::new(self, subject, access)
100 }
101}
102
103pub trait SizedGraph: Graph + Sized {
107 type IntoTriples: Iterator<
109 Item = Triple<
110 <Self as Graph>::Subject,
111 <Self as Graph>::Predicate,
112 <Self as Graph>::Object,
113 >,
114 >;
115
116 type IntoSubjects: Iterator<Item = (<Self as Graph>::Subject, Self::IntoPredicates)>;
118
119 type IntoPredicates: Iterator<Item = (<Self as Graph>::Predicate, Self::IntoObjects)>;
121
122 type IntoObjects: Iterator<Item = <Self as Graph>::Object>;
124
125 fn into_triples(self) -> Self::IntoTriples;
127
128 fn into_subjects(self) -> Self::IntoSubjects;
130
131 fn into_predicates(self, subject: &<Self as Graph>::Subject) -> Self::IntoPredicates;
134
135 fn into_objects(
138 self,
139 subject: &<Self as Graph>::Subject,
140 predicate: &<Self as Graph>::Predicate,
141 ) -> Self::IntoObjects;
142}
143
144pub trait MutableGraph: Graph {
146 fn insert(
148 &mut self,
149 triple: Triple<
150 <Self as Graph>::Subject,
151 <Self as Graph>::Predicate,
152 <Self as Graph>::Object,
153 >,
154 ) -> bool;
155
156 fn remove(
157 &mut self,
158 triple: Triple<
159 &<Self as Graph>::Subject,
160 &<Self as Graph>::Predicate,
161 &<Self as Graph>::Object,
162 >,
163 );
164
165 fn absorb<
169 G: SizedGraph<
170 Subject = <Self as Graph>::Subject,
171 Predicate = <Self as Graph>::Predicate,
172 Object = <Self as Graph>::Object,
173 >,
174 >(
175 &mut self,
176 other: G,
177 );
178}
179
180pub trait GraphTake<
181 T: ?Sized = <Self as Graph>::Subject,
182 U: ?Sized = <Self as Graph>::Predicate,
183 V: ?Sized = <Self as Graph>::Object,
184>: Graph
185{
186 #[allow(clippy::type_complexity)]
187 fn take(
188 &mut self,
189 triple: Triple<&T, &U, &V>,
190 ) -> Option<Triple<Self::Subject, Self::Predicate, Self::Object>>;
191
192 #[allow(clippy::type_complexity)]
193 fn take_match(
194 &mut self,
195 triple: Triple<Option<&T>, Option<&U>, Option<&V>>,
196 ) -> Option<Triple<Self::Subject, Self::Predicate, Self::Object>>;
197}