connortsui20 opened a new pull request, #965:
URL: https://github.com/apache/iceberg-rust/pull/965
(STILL A DRAFT)
Followup of #962
#962 Introduced a bug where it is not some of the methods allow for both
`StatusCode::OK` and `StatusCode::NO_CONTENT` as success cases, when in reality
it should be one or the other (this was me, sorry about that).
This PR attempts to unify the 3 different types of response helpers that
essentially all do the exact same thing slightly differently. The main addition
here is a function `query_catalog`:
```rust
// Queries the Iceberg REST catalog with the given `Request` and a
provided handler.
pub async fn query_catalog<R, H, Fut>(&self, mut request: Request,
handler: H) -> Result<R>
where
R: DeserializeOwned,
H: FnOnce(Response) -> Fut,
Fut: Future<Output = Result<R>>,
{
self.authenticate(&mut request).await?;
let response = self.client.execute(request).await?;
handler(response).await
}
```
By allowing each `Catalog` method to specify how they want to handle the
responses, it gets much finer control on the success/error cases as well as the
error messages. Previously, there were 3 functions that all did similar things:
```rust
pub async fn query<R: DeserializeOwned, E: DeserializeOwned +
Into<Error>>(
&self,
mut request: Request,
) -> Result<R> {
pub async fn execute<E: DeserializeOwned + Into<Error>>(
&self,
mut request: Request,
) -> Result<()> {
pub async fn do_execute<R, E: DeserializeOwned + Into<Error>>(
&self,
mut request: Request,
handler: impl FnOnce(&Response) -> Option<R>,
) -> Result<R> {
```
I'm also somewhat using this as a chance to refactor some other parts of
this crate, mainly documentation and examples.
(DRAFT)
@Xuanwo It would be great if I could get feedback on some of these proposed
changes before I keep going!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]