datafusion_delta_sharing/client/
response.rs1use std::fmt::{Display, Formatter};
4
5use serde::Deserialize;
6
7use crate::securable::{Schema, Share, Table};
8
9use super::action::{File, Metadata, Protocol};
10
11#[derive(Debug, Deserialize)]
13#[serde(rename_all = "camelCase")]
14pub struct ErrorResponse {
15 error_code: String,
16 message: String,
17}
18
19impl ErrorResponse {
20 pub fn error_code(&self) -> &str {
22 &self.error_code
23 }
24
25 pub fn _message(&self) -> &str {
27 &self.message
28 }
29}
30
31impl Display for ErrorResponse {
32 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
33 write!(f, "[{}] {}", self.error_code, self.message)
34 }
35}
36
37#[derive(Debug, Deserialize)]
39#[serde(rename_all = "camelCase")]
40pub struct ListSharesResponse {
41 items: Vec<Share>,
42 next_page_token: Option<String>,
43}
44
45impl ListSharesResponse {
46 pub fn items(&self) -> &[Share] {
48 &self.items
49 }
50
51 pub fn next_page_token(&self) -> Option<&str> {
53 self.next_page_token.as_deref()
54 }
55}
56
57impl IntoIterator for ListSharesResponse {
58 type Item = Share;
59 type IntoIter = std::vec::IntoIter<Self::Item>;
60
61 fn into_iter(self) -> Self::IntoIter {
62 self.items.into_iter()
63 }
64}
65
66#[derive(Debug, Deserialize)]
68pub struct GetShareResponse {
69 share: Share,
70}
71
72impl GetShareResponse {
73 pub fn share(&self) -> &Share {
75 &self.share
76 }
77}
78
79#[derive(Debug, Deserialize)]
81#[serde(rename_all = "camelCase")]
82pub struct ListSchemasResponse {
83 items: Vec<Schema>,
84 next_page_token: Option<String>,
85}
86
87impl ListSchemasResponse {
88 pub fn items(&self) -> &[Schema] {
90 &self.items
91 }
92
93 pub fn next_page_token(&self) -> Option<&str> {
95 self.next_page_token.as_deref()
96 }
97}
98
99impl IntoIterator for ListSchemasResponse {
100 type Item = Schema;
101 type IntoIter = std::vec::IntoIter<Self::Item>;
102
103 fn into_iter(self) -> Self::IntoIter {
104 self.items.into_iter()
105 }
106}
107
108#[derive(Debug, Deserialize)]
111#[serde(rename_all = "camelCase")]
112pub struct ListTablesResponse {
113 items: Vec<Table>,
114 next_page_token: Option<String>,
115}
116
117impl ListTablesResponse {
118 pub fn items(&self) -> &[Table] {
120 &self.items
121 }
122
123 pub fn next_page_token(&self) -> Option<&str> {
125 self.next_page_token.as_deref()
126 }
127}
128
129impl IntoIterator for ListTablesResponse {
130 type Item = Table;
131 type IntoIter = std::vec::IntoIter<Self::Item>;
132
133 fn into_iter(self) -> Self::IntoIter {
134 self.items.into_iter()
135 }
136}
137
138#[derive(Debug, Deserialize)]
141pub enum ParquetResponse {
142 #[serde(rename = "protocol")]
144 Protocol(Protocol),
145 #[serde(rename = "metaData")]
147 Metadata(Metadata),
148 #[serde(rename = "file")]
150 File(File),
151}
152
153impl ParquetResponse {
154 pub fn to_protocol(self) -> Option<Protocol> {
156 match self {
157 ParquetResponse::Protocol(p) => Some(p),
158 _ => None,
159 }
160 }
161
162 pub fn to_file(self) -> Option<File> {
164 match self {
165 ParquetResponse::File(f) => Some(f),
166 _ => None,
167 }
168 }
169
170 pub fn to_metadata(self) -> Option<Metadata> {
172 match self {
173 ParquetResponse::Metadata(m) => Some(m),
174 _ => None,
175 }
176 }
177}