Skip to main content

icydb_core/db/response/
paged.rs

1//! Module: response::paged
2//! Responsibility: paged load response payload contracts.
3//! Does not own: query execution, pagination planning, or cursor token protocol.
4//! Boundary: response DTOs returned by session/query execution APIs.
5
6use crate::{
7    db::{
8        executor::ExecutionTrace,
9        response::{ProjectedRow, Response},
10    },
11    traits::EntityKind,
12};
13
14///
15/// PagedLoadExecution
16///
17/// Cursor-paged load response with optional continuation cursor bytes.
18///
19
20#[derive(Debug)]
21pub struct PagedLoadExecution<E: EntityKind> {
22    response: Response<E>,
23    continuation_cursor: Option<Vec<u8>>,
24}
25
26impl<E: EntityKind> PagedLoadExecution<E> {
27    /// Create a paged load execution payload.
28    #[must_use]
29    pub const fn new(response: Response<E>, continuation_cursor: Option<Vec<u8>>) -> Self {
30        Self {
31            response,
32            continuation_cursor,
33        }
34    }
35
36    /// Borrow the paged response rows.
37    #[must_use]
38    pub const fn response(&self) -> &Response<E> {
39        &self.response
40    }
41
42    /// Borrow optional projected scalar rows for this page.
43    ///
44    /// Projection rows are present when scalar projection evaluation ran.
45    #[must_use]
46    pub fn projected_rows(&self) -> Option<&[ProjectedRow<E>]> {
47        self.response.projected_rows()
48    }
49
50    /// Borrow the optional continuation cursor bytes.
51    #[must_use]
52    pub fn continuation_cursor(&self) -> Option<&[u8]> {
53        self.continuation_cursor.as_deref()
54    }
55
56    /// Consume this payload and return `(response, continuation_cursor)`.
57    #[must_use]
58    pub fn into_parts(self) -> (Response<E>, Option<Vec<u8>>) {
59        (self.response, self.continuation_cursor)
60    }
61}
62
63impl<E: EntityKind> From<(Response<E>, Option<Vec<u8>>)> for PagedLoadExecution<E> {
64    fn from(value: (Response<E>, Option<Vec<u8>>)) -> Self {
65        let (response, continuation_cursor) = value;
66
67        Self::new(response, continuation_cursor)
68    }
69}
70
71impl<E: EntityKind> From<PagedLoadExecution<E>> for (Response<E>, Option<Vec<u8>>) {
72    fn from(value: PagedLoadExecution<E>) -> Self {
73        value.into_parts()
74    }
75}
76
77///
78/// PagedLoadExecutionWithTrace
79///
80/// Cursor-paged load response plus optional execution trace details.
81///
82
83#[derive(Debug)]
84pub struct PagedLoadExecutionWithTrace<E: EntityKind> {
85    execution: PagedLoadExecution<E>,
86    execution_trace: Option<ExecutionTrace>,
87}
88
89impl<E: EntityKind> PagedLoadExecutionWithTrace<E> {
90    /// Create a traced paged load execution payload.
91    #[must_use]
92    pub const fn new(
93        response: Response<E>,
94        continuation_cursor: Option<Vec<u8>>,
95        execution_trace: Option<ExecutionTrace>,
96    ) -> Self {
97        Self {
98            execution: PagedLoadExecution::new(response, continuation_cursor),
99            execution_trace,
100        }
101    }
102
103    /// Borrow the paged execution payload.
104    #[must_use]
105    pub const fn execution(&self) -> &PagedLoadExecution<E> {
106        &self.execution
107    }
108
109    /// Borrow the paged response rows.
110    #[must_use]
111    pub const fn response(&self) -> &Response<E> {
112        self.execution.response()
113    }
114
115    /// Borrow optional projected scalar rows for this page.
116    ///
117    /// Projection rows are present when scalar projection evaluation ran.
118    #[must_use]
119    pub fn projected_rows(&self) -> Option<&[ProjectedRow<E>]> {
120        self.execution.projected_rows()
121    }
122
123    /// Borrow the optional continuation cursor bytes.
124    #[must_use]
125    pub fn continuation_cursor(&self) -> Option<&[u8]> {
126        self.execution.continuation_cursor()
127    }
128
129    /// Borrow optional execution trace details.
130    #[must_use]
131    pub const fn execution_trace(&self) -> Option<&ExecutionTrace> {
132        self.execution_trace.as_ref()
133    }
134
135    /// Consume this payload and drop trace details.
136    #[must_use]
137    pub fn into_execution(self) -> PagedLoadExecution<E> {
138        self.execution
139    }
140
141    /// Consume this payload and return `(response, continuation_cursor, trace)`.
142    #[must_use]
143    pub fn into_parts(self) -> (Response<E>, Option<Vec<u8>>, Option<ExecutionTrace>) {
144        let (response, continuation_cursor) = self.execution.into_parts();
145
146        (response, continuation_cursor, self.execution_trace)
147    }
148}
149
150impl<E: EntityKind> From<(Response<E>, Option<Vec<u8>>, Option<ExecutionTrace>)>
151    for PagedLoadExecutionWithTrace<E>
152{
153    fn from(value: (Response<E>, Option<Vec<u8>>, Option<ExecutionTrace>)) -> Self {
154        let (response, continuation_cursor, execution_trace) = value;
155
156        Self::new(response, continuation_cursor, execution_trace)
157    }
158}
159
160impl<E: EntityKind> From<PagedLoadExecutionWithTrace<E>>
161    for (Response<E>, Option<Vec<u8>>, Option<ExecutionTrace>)
162{
163    fn from(value: PagedLoadExecutionWithTrace<E>) -> Self {
164        value.into_parts()
165    }
166}