Skip to main content

linkrs_storage/cursor/
vec_cursors.rs

1use linkrs_core::StorageError;
2
3/// Vertex cursor backed by a pre-materialized `Vec<Vertex>`.
4///
5/// This is the default implementation used when the storage backend does
6/// not yet provide a native lazy cursor.  It is semantically identical
7/// to calling [`StorageReader::scan_vertices`] upfront.
8#[derive(Debug)]
9pub struct VecVertexCursor {
10    iter: std::vec::IntoIter<linkrs_core::Vertex>,
11}
12
13impl VecVertexCursor {
14    pub fn new(vertices: Vec<linkrs_core::Vertex>) -> Self {
15        Self {
16            iter: vertices.into_iter(),
17        }
18    }
19}
20
21impl crate::cursor::VertexCursor for VecVertexCursor {
22    fn next_batch(&mut self, batch_size: usize) -> Result<Vec<linkrs_core::Vertex>, StorageError> {
23        Ok(self.iter.by_ref().take(batch_size).collect())
24    }
25}
26
27/// Edge cursor backed by a pre-materialized `Vec<Edge>`.
28#[derive(Debug)]
29pub struct VecEdgeCursor {
30    iter: std::vec::IntoIter<linkrs_core::Edge>,
31}
32
33impl VecEdgeCursor {
34    pub fn new(edges: Vec<linkrs_core::Edge>) -> Self {
35        Self {
36            iter: edges.into_iter(),
37        }
38    }
39}
40
41impl crate::cursor::EdgeCursor for VecEdgeCursor {
42    fn next_batch(&mut self, batch_size: usize) -> Result<Vec<linkrs_core::Edge>, StorageError> {
43        Ok(self.iter.by_ref().take(batch_size).collect())
44    }
45}