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::{executor::ExecutionTrace, response::Response},
8    traits::EntityKind,
9};
10
11///
12/// PagedLoadExecution
13///
14/// Cursor-paged load response with optional continuation cursor bytes.
15///
16
17#[derive(Debug)]
18pub struct PagedLoadExecution<E: EntityKind> {
19    response: Response<E>,
20    continuation_cursor: Option<Vec<u8>>,
21}
22
23impl<E: EntityKind> PagedLoadExecution<E> {
24    /// Create a paged load execution payload.
25    #[must_use]
26    pub const fn new(response: Response<E>, continuation_cursor: Option<Vec<u8>>) -> Self {
27        Self {
28            response,
29            continuation_cursor,
30        }
31    }
32
33    /// Borrow the paged response rows.
34    #[must_use]
35    pub const fn response(&self) -> &Response<E> {
36        &self.response
37    }
38
39    /// Borrow the optional continuation cursor bytes.
40    #[must_use]
41    pub fn continuation_cursor(&self) -> Option<&[u8]> {
42        self.continuation_cursor.as_deref()
43    }
44
45    /// Consume this payload and return `(response, continuation_cursor)`.
46    #[must_use]
47    pub fn into_parts(self) -> (Response<E>, Option<Vec<u8>>) {
48        (self.response, self.continuation_cursor)
49    }
50}
51
52impl<E: EntityKind> From<(Response<E>, Option<Vec<u8>>)> for PagedLoadExecution<E> {
53    fn from(value: (Response<E>, Option<Vec<u8>>)) -> Self {
54        let (response, continuation_cursor) = value;
55
56        Self::new(response, continuation_cursor)
57    }
58}
59
60impl<E: EntityKind> From<PagedLoadExecution<E>> for (Response<E>, Option<Vec<u8>>) {
61    fn from(value: PagedLoadExecution<E>) -> Self {
62        value.into_parts()
63    }
64}
65
66///
67/// PagedLoadExecutionWithTrace
68///
69/// Cursor-paged load response plus optional execution trace details.
70///
71
72#[derive(Debug)]
73pub struct PagedLoadExecutionWithTrace<E: EntityKind> {
74    execution: PagedLoadExecution<E>,
75    execution_trace: Option<ExecutionTrace>,
76}
77
78impl<E: EntityKind> PagedLoadExecutionWithTrace<E> {
79    /// Create a traced paged load execution payload.
80    #[must_use]
81    pub const fn new(
82        response: Response<E>,
83        continuation_cursor: Option<Vec<u8>>,
84        execution_trace: Option<ExecutionTrace>,
85    ) -> Self {
86        Self {
87            execution: PagedLoadExecution::new(response, continuation_cursor),
88            execution_trace,
89        }
90    }
91
92    /// Borrow the paged execution payload.
93    #[must_use]
94    pub const fn execution(&self) -> &PagedLoadExecution<E> {
95        &self.execution
96    }
97
98    /// Borrow the paged response rows.
99    #[must_use]
100    pub const fn response(&self) -> &Response<E> {
101        self.execution.response()
102    }
103
104    /// Borrow the optional continuation cursor bytes.
105    #[must_use]
106    pub fn continuation_cursor(&self) -> Option<&[u8]> {
107        self.execution.continuation_cursor()
108    }
109
110    /// Borrow optional execution trace details.
111    #[must_use]
112    pub const fn execution_trace(&self) -> Option<&ExecutionTrace> {
113        self.execution_trace.as_ref()
114    }
115
116    /// Consume this payload and drop trace details.
117    #[must_use]
118    pub fn into_execution(self) -> PagedLoadExecution<E> {
119        self.execution
120    }
121
122    /// Consume this payload and return `(response, continuation_cursor, trace)`.
123    #[must_use]
124    pub fn into_parts(self) -> (Response<E>, Option<Vec<u8>>, Option<ExecutionTrace>) {
125        let (response, continuation_cursor) = self.execution.into_parts();
126
127        (response, continuation_cursor, self.execution_trace)
128    }
129}
130
131impl<E: EntityKind> From<(Response<E>, Option<Vec<u8>>, Option<ExecutionTrace>)>
132    for PagedLoadExecutionWithTrace<E>
133{
134    fn from(value: (Response<E>, Option<Vec<u8>>, Option<ExecutionTrace>)) -> Self {
135        let (response, continuation_cursor, execution_trace) = value;
136
137        Self::new(response, continuation_cursor, execution_trace)
138    }
139}
140
141impl<E: EntityKind> From<PagedLoadExecutionWithTrace<E>>
142    for (Response<E>, Option<Vec<u8>>, Option<ExecutionTrace>)
143{
144    fn from(value: PagedLoadExecutionWithTrace<E>) -> Self {
145        value.into_parts()
146    }
147}