Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement optional async support and remove nested result type in response #150

Merged
merged 40 commits into from
Oct 31, 2024

Conversation

wfraser
Copy link
Member

@wfraser wfraser commented Apr 22, 2024

The new features controlling this are async_routes which enables compiling the async functions, and and default_async_client which enables a default HTTP client based on reqwest.

For most current use cases this should be a fairly seamless transition, as I've made great pains to ensure that types are in the same locations unless you use the new features.

The one thing which will require manual updates is the return value from most functions has changed from Result<Result<T, E, dropbox_sdk::Error> to Result<T, dropbox_sdk::Error<E>>. That is, code which previously did:

match get_metadata(&client, &arg) {
    Ok(Ok(metadata)) => { ... }
    Ok(Err(api_error)) => { /* the request succeeded, but the API returned an error */ }
    Err(e) => { /* the request failed entirely */ }
}

should now look like:

match get_metadata(&client, &arg) {
    Ok(metadata) => { ... }
    Err(Error::Api(api_error)) => { /* the request succeeded, but the API returned an error */ }
    Err(e) => { /* the request failed entirely */ }
}

The thing is, most code doesn't look like this and just wants to use the ? operator to pass errors up, so that's now easier to do.

If users have implemented a custom HTTP client, they will need to rework it a lot, as the HTTP client traits have been completely rewritten and are very different. That said, the new trait moves more things to the helper code, so implementing a custom client should be simpler now.

This change violates our MSRV policy a bit (requiring rust 1.75.0 which is only 10 months old instead of the desired 12) so I'm proposing to land this as a beta release for now.

Checklist

General Contributing

  • I have read the Code of Conduct and signed the CLA.
  • I have added an entry to the RELEASE_NOTES.md file, or believe it's not necessary for this change.

Validation

A copy of the demo example has been made (called demo-async) which uses the default async client, which acts as a decent integration test.

The CI scripts have been updated to check things under both sync and async modes.

wfraser added 27 commits April 1, 2024 13:04
This creates async HTTP client traits which mirror the existing sync
ones.

It also reimplements sync in terms of async, since we can use
now_or_never as an escape hatch to get back to sync land, but the
reverse is not possible.

One ugly wart is that there's no good escape hatch to convert the
sync-reader-in-async-wrapper response body back to a sync reader other
than an unsafe pointer cast.

No async routes generated yet; that's coming next.
this helps users who have no-default-features but also default_client; they want all the routes in the old places
Then this can be used by the oauth2 code to provide better responses when tokens are bogus
We're using HTTP2 where it's just a repeat of the code number anyway, so it adds no value.
not just 2.0.0; the signature of ureq::Response::into_reader() was changed in 2.5.0
@wfraser
Copy link
Member Author

wfraser commented Oct 31, 2024

As long as we're doing this big of a change, might as well do the error-flattening change too.

@wfraser wfraser changed the title implement optional async support implement optional async support and remove nested result type in response Oct 31, 2024
@wfraser wfraser merged commit 8bbab23 into dropbox:master Oct 31, 2024
2 checks passed
@wfraser wfraser deleted the async-mode branch October 31, 2024 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant