icydb_core/db/response/
paged.rs1use crate::{
7 db::{
8 executor::ExecutionTrace,
9 response::{ProjectedRow, Response},
10 },
11 traits::EntityKind,
12};
13
14#[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 #[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 #[must_use]
38 pub const fn response(&self) -> &Response<E> {
39 &self.response
40 }
41
42 #[must_use]
46 pub fn projected_rows(&self) -> Option<&[ProjectedRow<E>]> {
47 self.response.projected_rows()
48 }
49
50 #[must_use]
52 pub fn continuation_cursor(&self) -> Option<&[u8]> {
53 self.continuation_cursor.as_deref()
54 }
55
56 #[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#[derive(Debug)]
84pub struct PagedLoadExecutionWithTrace<E: EntityKind> {
85 execution: PagedLoadExecution<E>,
86 execution_trace: Option<ExecutionTrace>,
87}
88
89impl<E: EntityKind> PagedLoadExecutionWithTrace<E> {
90 #[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 #[must_use]
105 pub const fn execution(&self) -> &PagedLoadExecution<E> {
106 &self.execution
107 }
108
109 #[must_use]
111 pub const fn response(&self) -> &Response<E> {
112 self.execution.response()
113 }
114
115 #[must_use]
119 pub fn projected_rows(&self) -> Option<&[ProjectedRow<E>]> {
120 self.execution.projected_rows()
121 }
122
123 #[must_use]
125 pub fn continuation_cursor(&self) -> Option<&[u8]> {
126 self.execution.continuation_cursor()
127 }
128
129 #[must_use]
131 pub const fn execution_trace(&self) -> Option<&ExecutionTrace> {
132 self.execution_trace.as_ref()
133 }
134
135 #[must_use]
137 pub fn into_execution(self) -> PagedLoadExecution<E> {
138 self.execution
139 }
140
141 #[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}