1use std::marker::PhantomData;
16
17use crate::{
18 field::FieldData,
19 raw::{RawEdgeIndexIterator, RawVertexIndexIterator},
20 types::EdgeUid,
21};
22
23use super::{EdgeCursor, VertexCursor};
24
25#[must_use = "iterators are lazy and do nothing unless consumed"]
29pub struct IntoVertexIter<T> {
30 cursor: T,
31}
32
33impl<T> IntoVertexIter<T> {
34 pub(super) fn new(cursor: T) -> IntoVertexIter<T> {
35 IntoVertexIter { cursor }
36 }
37}
38
39impl<T: VertexCursor> Iterator for IntoVertexIter<T> {
40 type Item = (i64, String, Vec<FieldData>);
41
42 fn next(&mut self) -> Option<(i64, String, Vec<FieldData>)> {
43 if !self.cursor.is_valid() {
44 return None;
45 }
46 let id = self.cursor.id().expect("valid iterator should get value");
47 let label = self
48 .cursor
49 .label()
50 .expect("valid iterator should get value");
51 let fields = self
52 .cursor
53 .all_fields()
54 .map(|all| all.into_iter().map(|f| f.1).collect())
55 .expect("valid iterator should get value");
56 let _ = self.cursor.seek_to_next();
57 Some((id, label, fields))
58 }
59}
60
61#[must_use = "iterators are lazy and do nothing unless consumed"]
65pub struct IntoVertexIds<T> {
66 cursor: T,
67}
68
69impl<T> IntoVertexIds<T> {
70 pub(super) fn new(cursor: T) -> IntoVertexIds<T> {
71 IntoVertexIds { cursor }
72 }
73}
74
75impl<T: VertexCursor> Iterator for IntoVertexIds<T> {
76 type Item = i64;
77 fn next(&mut self) -> Option<i64> {
78 if !self.cursor.is_valid() {
79 return None;
80 }
81 let id = self.cursor.id().expect("valid iterator should get value");
82 let _ = self.cursor.seek_to_next();
83 Some(id)
84 }
85}
86
87#[must_use = "iterators are lazy and do nothing unless consumed"]
91pub struct IntoVertexLabelIds<T> {
92 cursor: T,
93}
94
95impl<T> IntoVertexLabelIds<T> {
96 pub(super) fn new(cursor: T) -> IntoVertexLabelIds<T> {
97 IntoVertexLabelIds { cursor }
98 }
99}
100
101impl<T: VertexCursor> Iterator for IntoVertexLabelIds<T> {
102 type Item = u16;
103 fn next(&mut self) -> Option<u16> {
104 if !self.cursor.is_valid() {
105 return None;
106 }
107 let lid = self.cursor.lid().expect("valid iterator should get value");
108 let _ = self.cursor.seek_to_next();
109 Some(lid)
110 }
111}
112
113#[must_use = "iterators are lazy and do nothing unless consumed"]
117pub struct IntoVertexLabels<T> {
118 cursor: T,
119}
120
121impl<T> IntoVertexLabels<T> {
122 pub(super) fn new(cursor: T) -> IntoVertexLabels<T> {
123 IntoVertexLabels { cursor }
124 }
125}
126
127impl<T: VertexCursor> Iterator for IntoVertexLabels<T> {
128 type Item = String;
129 fn next(&mut self) -> Option<String> {
130 if !self.cursor.is_valid() {
131 return None;
132 }
133 let label = self
134 .cursor
135 .label()
136 .expect("valid iterator should get value");
137 let _ = self.cursor.seek_to_next();
138 Some(label)
139 }
140}
141
142#[must_use = "iterators are lazy and do nothing unless consumed"]
146pub struct IntoVertexFields<T> {
147 cursor: T,
148}
149
150impl<T> IntoVertexFields<T> {
151 pub(super) fn new(cursor: T) -> IntoVertexFields<T> {
152 IntoVertexFields { cursor }
153 }
154}
155
156impl<T: VertexCursor> Iterator for IntoVertexFields<T> {
157 type Item = Vec<FieldData>;
158 fn next(&mut self) -> Option<Vec<FieldData>> {
159 if !self.cursor.is_valid() {
160 return None;
161 }
162 let fields = self
163 .cursor
164 .all_fields()
165 .map(|all| all.into_iter().map(|f| f.1).collect())
166 .expect("valid iterator should get value");
167 let _ = self.cursor.seek_to_next();
168 Some(fields)
169 }
170}
171
172#[must_use = "iterators are lazy and do nothing unless consumed"]
176pub struct IntoEdgeIter<T> {
177 cursor: T,
178}
179
180impl<T> IntoEdgeIter<T> {
181 pub(super) fn new(cursor: T) -> IntoEdgeIter<T> {
182 IntoEdgeIter { cursor }
183 }
184}
185
186impl<T: EdgeCursor> Iterator for IntoEdgeIter<T> {
187 type Item = (EdgeUid, String, Vec<FieldData>);
188 fn next(&mut self) -> Option<(EdgeUid, String, Vec<FieldData>)> {
189 if !self.cursor.is_valid() {
190 return None;
191 }
192 let uid = self.cursor.uid().expect("valid iterator should get value");
193 let label = self
194 .cursor
195 .label()
196 .expect("valid iterator should get value");
197 let fields = self
198 .cursor
199 .all_fields()
200 .map(|all| all.into_iter().map(|f| f.1).collect())
201 .expect("valid iterator should get value");
202 let _ = self.cursor.seek_to_next();
203 Some((uid, label, fields))
204 }
205}
206
207#[must_use = "iterators are lazy and do nothing unless consumed"]
211pub struct IntoEdgeUids<T> {
212 cursor: T,
213}
214
215impl<T> IntoEdgeUids<T> {
216 pub(super) fn new(cursor: T) -> IntoEdgeUids<T> {
217 IntoEdgeUids { cursor }
218 }
219}
220
221impl<T: EdgeCursor> Iterator for IntoEdgeUids<T> {
222 type Item = EdgeUid;
223 fn next(&mut self) -> Option<EdgeUid> {
224 if !self.cursor.is_valid() {
225 return None;
226 }
227 let uid = self.cursor.uid().expect("valid iterator should get value");
228 let _ = self.cursor.seek_to_next();
229 Some(uid)
230 }
231}
232
233#[must_use = "iterators are lazy and do nothing unless consumed"]
237pub struct IntoEdgeSrcs<T> {
238 cursor: T,
239}
240
241impl<T> IntoEdgeSrcs<T> {
242 pub(super) fn new(cursor: T) -> IntoEdgeSrcs<T> {
243 IntoEdgeSrcs { cursor }
244 }
245}
246
247impl<T: EdgeCursor> Iterator for IntoEdgeSrcs<T> {
248 type Item = i64;
249 fn next(&mut self) -> Option<i64> {
250 if !self.cursor.is_valid() {
251 return None;
252 }
253 let src = self.cursor.src().expect("valid iterator should get value");
254 let _ = self.cursor.seek_to_next();
255 Some(src)
256 }
257}
258
259#[must_use = "iterators are lazy and do nothing unless consumed"]
263pub struct IntoEdgeDsts<T> {
264 cursor: T,
265}
266
267impl<T> IntoEdgeDsts<T> {
268 pub(super) fn new(cursor: T) -> IntoEdgeDsts<T> {
269 IntoEdgeDsts { cursor }
270 }
271}
272
273impl<T: EdgeCursor> Iterator for IntoEdgeDsts<T> {
274 type Item = i64;
275 fn next(&mut self) -> Option<i64> {
276 if !self.cursor.is_valid() {
277 return None;
278 }
279 let dst = self.cursor.dst().expect("valid iterator should get value");
280 let _ = self.cursor.seek_to_next();
281 Some(dst)
282 }
283}
284
285#[must_use = "iterators are lazy and do nothing unless consumed"]
289pub struct IntoEdgeIds<T> {
290 cursor: T,
291}
292
293impl<T> IntoEdgeIds<T> {
294 pub(super) fn new(cursor: T) -> IntoEdgeIds<T> {
295 IntoEdgeIds { cursor }
296 }
297}
298
299impl<T: EdgeCursor> Iterator for IntoEdgeIds<T> {
300 type Item = i64;
301 fn next(&mut self) -> Option<i64> {
302 if !self.cursor.is_valid() {
303 return None;
304 }
305 let eid = self.cursor.eid().expect("valid iterator should get value");
306 let _ = self.cursor.seek_to_next();
307 Some(eid)
308 }
309}
310
311#[must_use = "iterators are lazy and do nothing unless consumed"]
315pub struct IntoEdgeTemporalIds<T> {
316 cursor: T,
317}
318
319impl<T> IntoEdgeTemporalIds<T> {
320 pub(super) fn new(cursor: T) -> IntoEdgeTemporalIds<T> {
321 IntoEdgeTemporalIds { cursor }
322 }
323}
324
325impl<T: EdgeCursor> Iterator for IntoEdgeTemporalIds<T> {
326 type Item = i64;
327 fn next(&mut self) -> Option<i64> {
328 if !self.cursor.is_valid() {
329 return None;
330 }
331 let tid = self.cursor.tid().expect("valid iterator should get value");
332 let _ = self.cursor.seek_to_next();
333 Some(tid)
334 }
335}
336
337#[must_use = "iterators are lazy and do nothing unless consumed"]
341pub struct IntoEdgeLabelIds<T> {
342 cursor: T,
343}
344
345impl<T> IntoEdgeLabelIds<T> {
346 pub(super) fn new(cursor: T) -> IntoEdgeLabelIds<T> {
347 IntoEdgeLabelIds { cursor }
348 }
349}
350
351impl<T: EdgeCursor> Iterator for IntoEdgeLabelIds<T> {
352 type Item = u16;
353 fn next(&mut self) -> Option<u16> {
354 if !self.cursor.is_valid() {
355 return None;
356 }
357 let lid = self.cursor.lid().expect("valid iterator should get value");
358 let _ = self.cursor.seek_to_next();
359 Some(lid)
360 }
361}
362
363#[must_use = "iterators are lazy and do nothing unless consumed"]
367pub struct IntoEdgeLabels<T> {
368 cursor: T,
369}
370
371impl<T> IntoEdgeLabels<T> {
372 pub(super) fn new(cursor: T) -> IntoEdgeLabels<T> {
373 IntoEdgeLabels { cursor }
374 }
375}
376
377impl<T: EdgeCursor> Iterator for IntoEdgeLabels<T> {
378 type Item = String;
379 fn next(&mut self) -> Option<String> {
380 if !self.cursor.is_valid() {
381 return None;
382 }
383 let label = self
384 .cursor
385 .label()
386 .expect("valid iterator should get value");
387 let _ = self.cursor.seek_to_next();
388 Some(label)
389 }
390}
391
392#[must_use = "iterators are lazy and do nothing unless consumed"]
396pub struct IntoEdgeFields<T> {
397 cursor: T,
398}
399
400impl<T> IntoEdgeFields<T> {
401 pub(super) fn new(cursor: T) -> IntoEdgeFields<T> {
402 IntoEdgeFields { cursor }
403 }
404}
405
406impl<T: EdgeCursor> Iterator for IntoEdgeFields<T> {
407 type Item = Vec<FieldData>;
408 fn next(&mut self) -> Option<Vec<FieldData>> {
409 if !self.cursor.is_valid() {
410 return None;
411 }
412 let fields = self
413 .cursor
414 .all_fields()
415 .map(|all| all.into_iter().map(|f| f.1).collect())
416 .expect("valid iterator should get value");
417 let _ = self.cursor.seek_to_next();
418 Some(fields)
419 }
420}
421
422#[must_use = "iterators are lazy and do nothing unless consumed"]
428pub struct VertexIndexIter<'txn> {
429 inner: RawVertexIndexIterator,
430 _marker: PhantomData<&'txn ()>,
431}
432
433impl<'txn> VertexIndexIter<'txn> {
434 pub(crate) fn new(raw_index_iter: RawVertexIndexIterator) -> VertexIndexIter<'txn> {
435 VertexIndexIter {
436 inner: raw_index_iter,
437 _marker: PhantomData,
438 }
439 }
440}
441
442impl<'txn> Iterator for VertexIndexIter<'txn> {
443 type Item = (i64, FieldData);
444 fn next(&mut self) -> Option<(i64, FieldData)> {
445 if !self.inner.is_valid() {
446 return None;
447 }
448 let id = self
449 .inner
450 .get_id()
451 .expect("valid iterator should get value");
452 let fd = self
453 .inner
454 .get_index_value()
455 .map(|raw| FieldData::from_raw_field_data(&raw))
456 .expect("valid iterator should get value");
457 let _ = self.inner.next();
458 Some((id, fd))
459 }
460}
461
462#[must_use = "iterators are lazy and do nothing unless consumed"]
468pub struct VertexIndexIds<'txn> {
469 inner: RawVertexIndexIterator,
470 _marker: PhantomData<&'txn ()>,
471}
472
473impl<'txn> VertexIndexIds<'txn> {
474 pub(crate) fn new(raw_index_iter: RawVertexIndexIterator) -> VertexIndexIds<'txn> {
475 VertexIndexIds {
476 inner: raw_index_iter,
477 _marker: PhantomData,
478 }
479 }
480}
481
482impl<'txn> Iterator for VertexIndexIds<'txn> {
483 type Item = i64;
484 fn next(&mut self) -> Option<i64> {
485 if !self.inner.is_valid() {
486 return None;
487 }
488 let id = self
489 .inner
490 .get_id()
491 .expect("valid iterator should get value");
492 let _ = self.inner.next();
493 Some(id)
494 }
495}
496
497#[must_use = "iterators are lazy and do nothing unless consumed"]
503pub struct VertexIndexValues<'txn> {
504 inner: RawVertexIndexIterator,
505 _marker: PhantomData<&'txn ()>,
506}
507
508impl<'txn> VertexIndexValues<'txn> {
509 pub(crate) fn new(raw_index_iter: RawVertexIndexIterator) -> VertexIndexValues<'txn> {
510 VertexIndexValues {
511 inner: raw_index_iter,
512 _marker: PhantomData,
513 }
514 }
515}
516
517impl<'txn> Iterator for VertexIndexValues<'txn> {
518 type Item = FieldData;
519 fn next(&mut self) -> Option<FieldData> {
520 if !self.inner.is_valid() {
521 return None;
522 }
523 let fd = self
524 .inner
525 .get_index_value()
526 .map(|raw| FieldData::from_raw_field_data(&raw))
527 .expect("valid iterator should get value");
528 let _ = self.inner.next();
529 Some(fd)
530 }
531}
532
533#[must_use = "iterators are lazy and do nothing unless consumed"]
539pub struct EdgeIndexIter<'txn> {
540 inner: RawEdgeIndexIterator,
541 _marker: PhantomData<&'txn ()>,
542}
543
544impl<'txn> EdgeIndexIter<'txn> {
545 pub(crate) fn new(raw_index_iter: RawEdgeIndexIterator) -> EdgeIndexIter<'txn> {
546 EdgeIndexIter {
547 inner: raw_index_iter,
548 _marker: PhantomData,
549 }
550 }
551}
552
553impl<'txn> Iterator for EdgeIndexIter<'txn> {
554 type Item = (EdgeUid, FieldData);
555 fn next(&mut self) -> Option<(EdgeUid, FieldData)> {
556 if !self.inner.is_valid() {
557 return None;
558 }
559 let uid = self
560 .inner
561 .get_uid()
562 .map(|raw| EdgeUid::from_raw(&raw))
563 .expect("valid iterator should get value");
564 let fd = self
565 .inner
566 .get_index_value()
567 .map(|raw| FieldData::from_raw_field_data(&raw))
568 .expect("valid iterator should get value");
569 let _ = self.inner.next();
570 Some((uid, fd))
571 }
572}
573
574#[must_use = "iterators are lazy and do nothing unless consumed"]
580pub struct EdgeIndexUids<'txn> {
581 inner: RawEdgeIndexIterator,
582 _marker: PhantomData<&'txn ()>,
583}
584
585impl<'txn> EdgeIndexUids<'txn> {
586 pub(crate) fn new(raw_index_iter: RawEdgeIndexIterator) -> EdgeIndexUids<'txn> {
587 EdgeIndexUids {
588 inner: raw_index_iter,
589 _marker: PhantomData,
590 }
591 }
592}
593
594impl<'txn> Iterator for EdgeIndexUids<'txn> {
595 type Item = EdgeUid;
596 fn next(&mut self) -> Option<EdgeUid> {
597 if !self.inner.is_valid() {
598 return None;
599 }
600 let uid = self
601 .inner
602 .get_uid()
603 .map(|raw| EdgeUid::from_raw(&raw))
604 .expect("valid iterator should get value");
605 let _ = self.inner.next();
606 Some(uid)
607 }
608}
609
610#[must_use = "iterators are lazy and do nothing unless consumed"]
616pub struct EdgeIndexSrcs<'txn> {
617 inner: RawEdgeIndexIterator,
618 _marker: PhantomData<&'txn ()>,
619}
620
621impl<'txn> EdgeIndexSrcs<'txn> {
622 pub(crate) fn new(raw_index_iter: RawEdgeIndexIterator) -> EdgeIndexSrcs<'txn> {
623 EdgeIndexSrcs {
624 inner: raw_index_iter,
625 _marker: PhantomData,
626 }
627 }
628}
629
630impl<'txn> Iterator for EdgeIndexSrcs<'txn> {
631 type Item = i64;
632 fn next(&mut self) -> Option<i64> {
633 if !self.inner.is_valid() {
634 return None;
635 }
636 let src = self
637 .inner
638 .get_src()
639 .expect("valid iterator should get value");
640 let _ = self.inner.next();
641 Some(src)
642 }
643}
644
645#[must_use = "iterators are lazy and do nothing unless consumed"]
651pub struct EdgeIndexDsts<'txn> {
652 inner: RawEdgeIndexIterator,
653 _marker: PhantomData<&'txn ()>,
654}
655
656impl<'txn> EdgeIndexDsts<'txn> {
657 pub(crate) fn new(raw_index_iter: RawEdgeIndexIterator) -> EdgeIndexDsts<'txn> {
658 EdgeIndexDsts {
659 inner: raw_index_iter,
660 _marker: PhantomData,
661 }
662 }
663}
664
665impl<'txn> Iterator for EdgeIndexDsts<'txn> {
666 type Item = i64;
667 fn next(&mut self) -> Option<i64> {
668 if !self.inner.is_valid() {
669 return None;
670 }
671 let dst = self
672 .inner
673 .get_dst()
674 .expect("valid iterator should get value");
675 let _ = self.inner.next();
676 Some(dst)
677 }
678}
679
680#[must_use = "iterators are lazy and do nothing unless consumed"]
686pub struct EdgeIndexLabelIds<'txn> {
687 inner: RawEdgeIndexIterator,
688 _marker: PhantomData<&'txn ()>,
689}
690
691impl<'txn> EdgeIndexLabelIds<'txn> {
692 pub(crate) fn new(raw_index_iter: RawEdgeIndexIterator) -> EdgeIndexLabelIds<'txn> {
693 EdgeIndexLabelIds {
694 inner: raw_index_iter,
695 _marker: PhantomData,
696 }
697 }
698}
699
700impl<'txn> Iterator for EdgeIndexLabelIds<'txn> {
701 type Item = u16;
702 fn next(&mut self) -> Option<u16> {
703 if !self.inner.is_valid() {
704 return None;
705 }
706 let lid = self
707 .inner
708 .get_label_id()
709 .expect("valid iterator should get value");
710 let _ = self.inner.next();
711 Some(lid)
712 }
713}
714
715#[must_use = "iterators are lazy and do nothing unless consumed"]
721pub struct EdgeIndexEdgeIds<'txn> {
722 inner: RawEdgeIndexIterator,
723 _marker: PhantomData<&'txn ()>,
724}
725
726impl<'txn> EdgeIndexEdgeIds<'txn> {
727 pub(crate) fn new(raw_index_iter: RawEdgeIndexIterator) -> EdgeIndexEdgeIds<'txn> {
728 EdgeIndexEdgeIds {
729 inner: raw_index_iter,
730 _marker: PhantomData,
731 }
732 }
733}
734
735impl<'txn> Iterator for EdgeIndexEdgeIds<'txn> {
736 type Item = i64;
737 fn next(&mut self) -> Option<i64> {
738 if !self.inner.is_valid() {
739 return None;
740 }
741 let eid = self
742 .inner
743 .get_edge_id()
744 .expect("valid iterator should get value");
745 let _ = self.inner.next();
746 Some(eid)
747 }
748}
749
750#[must_use = "iterators are lazy and do nothing unless consumed"]
756pub struct EdgeIndexValues<'txn> {
757 inner: RawEdgeIndexIterator,
758 _marker: PhantomData<&'txn ()>,
759}
760
761impl<'txn> EdgeIndexValues<'txn> {
762 pub(crate) fn new(raw_index_iter: RawEdgeIndexIterator) -> EdgeIndexValues<'txn> {
763 EdgeIndexValues {
764 inner: raw_index_iter,
765 _marker: PhantomData,
766 }
767 }
768}
769
770impl<'txn> Iterator for EdgeIndexValues<'txn> {
771 type Item = FieldData;
772 fn next(&mut self) -> Option<FieldData> {
773 if !self.inner.is_valid() {
774 return None;
775 }
776 let fd = self
777 .inner
778 .get_index_value()
779 .map(|raw| FieldData::from_raw_field_data(&raw))
780 .expect("valid iterator should get value");
781 let _ = self.inner.next();
782 Some(fd)
783 }
784}