Suggestion: Use futures_io traits in public API#268
Draft
rrauch wants to merge 2 commits into
Draft
Conversation
…nts in public API
…:oneshot, remove tokio dependency
Member
|
Out of curiosity is there a major benefit to this? We're relatively new to the Rust ecosystem. It seems like there are really only two maintained runtimes with Tokio being recommended for 99% of uses. Relaxing it in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Submitting this as a draft to get your thoughts.
This swaps
tokio::io::{AsyncRead, AsyncWrite}forfutures_io::{AsyncRead, AsyncWrite}in the public API.In the case of
sia_sdkit entirely removes Tokio as a hard dependency.What's the point?
Tokio comes with its own async I/O reader & writer traits:
tokio::io::{AsyncRead, AsyncWrite}, whilefutures_io::{AsyncRead, AsyncWrite}are the runtime-agnostic versions of these traits. Both trait-families are very similar, but not identical. Thefutures_iotraits are part of thefuturesproject, basically the ecosystem's common ground for async that isn't tied to any specific runtime. The futures-crates are small, composable, and it's what most crates use when they want to stay neutral.tokio_utilcomes with aCompatwrapper that turnstokio::io::{AsyncRead, AsyncWrite}into theirfutures_ioequivalent (and vice-versa).By switching to the
futures_iotraits, Tokio becomes more of an implementation detail than a fixed part of the API.What has changed
In terms of what changes where:
sia_sdk- Tokio goes away as a dependency completely. Also re-exportsfutures_io::{AsyncRead, AsyncWrite}so consumers don't need to pull in the crate separately.indexd- still uses Tokio internally (usesCompatin some places), but the public API no longer forces Tokio types on consumers. This opens the door to relaxing the Tokio dependency further in the future.indexd_ffi- Keeping the internal Tokio runtime here makes sense. Adapted to use new API types internally.sia-sdk-derive- not affectedLet me know what you think, happy to rework or close this if it's not the direction you want to go.