use crate::{
db::{
diagnostics::{ExecutionMetrics, ExecutionTrace},
response::{EntityResponse, Row},
},
traits::EntityKind,
};
#[derive(Debug)]
pub struct PagedLoadExecution<E: EntityKind> {
response: EntityResponse<E>,
continuation_cursor: Option<Vec<u8>>,
}
impl<E: EntityKind> PagedLoadExecution<E> {
#[must_use]
pub const fn new(response: EntityResponse<E>, continuation_cursor: Option<Vec<u8>>) -> Self {
Self {
response,
continuation_cursor,
}
}
#[must_use]
pub const fn response(&self) -> &EntityResponse<E> {
&self.response
}
pub fn iter(&self) -> std::slice::Iter<'_, Row<E>> {
self.response.iter()
}
#[must_use]
pub fn continuation_cursor(&self) -> Option<&[u8]> {
self.continuation_cursor.as_deref()
}
#[must_use]
pub fn into_parts(self) -> (EntityResponse<E>, Option<Vec<u8>>) {
(self.response, self.continuation_cursor)
}
}
impl<'a, E: EntityKind> IntoIterator for &'a PagedLoadExecution<E> {
type Item = &'a Row<E>;
type IntoIter = std::slice::Iter<'a, Row<E>>;
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}
#[derive(Debug)]
pub struct PagedLoadExecutionWithTrace<E: EntityKind> {
response: EntityResponse<E>,
continuation_cursor: Option<Vec<u8>>,
execution_trace: Option<ExecutionTrace>,
}
impl<E: EntityKind> PagedLoadExecutionWithTrace<E> {
#[must_use]
pub const fn new(
response: EntityResponse<E>,
continuation_cursor: Option<Vec<u8>>,
execution_trace: Option<ExecutionTrace>,
) -> Self {
Self {
response,
continuation_cursor,
execution_trace,
}
}
#[must_use]
pub const fn response(&self) -> &EntityResponse<E> {
&self.response
}
pub fn iter(&self) -> std::slice::Iter<'_, Row<E>> {
self.response.iter()
}
#[must_use]
pub fn continuation_cursor(&self) -> Option<&[u8]> {
self.continuation_cursor.as_deref()
}
#[must_use]
pub const fn execution_trace(&self) -> Option<&ExecutionTrace> {
self.execution_trace.as_ref()
}
#[must_use]
pub fn execution_metrics(&self) -> Option<ExecutionMetrics> {
self.execution_trace.as_ref().map(ExecutionTrace::metrics)
}
#[must_use]
pub fn into_execution(self) -> PagedLoadExecution<E> {
PagedLoadExecution {
response: self.response,
continuation_cursor: self.continuation_cursor,
}
}
#[must_use]
pub fn into_parts(self) -> (EntityResponse<E>, Option<Vec<u8>>, Option<ExecutionTrace>) {
(
self.response,
self.continuation_cursor,
self.execution_trace,
)
}
}
impl<'a, E: EntityKind> IntoIterator for &'a PagedLoadExecutionWithTrace<E> {
type Item = &'a Row<E>;
type IntoIter = std::slice::Iter<'a, Row<E>>;
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}