Skip to main content

cartel_sqlite/engine/api/
batches.rs

1use crate::{row, runtime};
2use std::{marker, mem, ops, result, slice};
3
4pub(crate) struct Arena<'owner> {
5    storage: &'owner mut runtime::raw::Span,
6}
7
8impl<'owner> Arena<'owner> {
9    pub(crate) const fn from_span(storage: &'owner mut runtime::raw::Span) -> Self {
10        Self { storage }
11    }
12
13    pub(crate) fn retain<T: Copy>(
14        &mut self,
15        rows: usize,
16    ) -> result::Result<row::raw::Retainer<'_, T>, crate::Error> {
17        row::raw::Retainer::new(self.storage, rows)
18    }
19}
20
21const _: () = assert!(mem::size_of::<Arena<'static>>() == mem::size_of::<usize>());
22
23/// A fixed-arena collection whose row views borrow the issuing local runtime.
24pub struct Rows<'arena, R: row::raw::Decode + 'arena> {
25    rows: &'arena [R::Borrowed<'arena>],
26    row: marker::PhantomData<fn() -> R>,
27}
28
29impl<'arena, R: row::raw::Decode + 'arena> Rows<'arena, R> {
30    pub(crate) const fn new(rows: &'arena [R::Borrowed<'arena>]) -> Self {
31        Self {
32            rows,
33            row: marker::PhantomData,
34        }
35    }
36
37    pub fn as_slice(&self) -> &'arena [R::Borrowed<'arena>] {
38        self.rows
39    }
40
41    pub fn len(&self) -> usize {
42        self.rows.len()
43    }
44
45    pub fn is_empty(&self) -> bool {
46        self.rows.is_empty()
47    }
48
49    pub fn iter(&self) -> slice::Iter<'arena, R::Borrowed<'arena>> {
50        self.rows.iter()
51    }
52}
53
54impl<'arena, R: row::raw::Decode + 'arena> ops::Deref for Rows<'arena, R> {
55    type Target = [R::Borrowed<'arena>];
56
57    fn deref(&self) -> &Self::Target {
58        self.rows
59    }
60}