Skip to content

Make RandomAccess returned owned futures#27

Open
cowlicks wants to merge 14 commits intomasterfrom
owned-futures
Open

Make RandomAccess returned owned futures#27
cowlicks wants to merge 14 commits intomasterfrom
owned-futures

Conversation

@cowlicks
Copy link
Member

@cowlicks cowlicks commented Feb 24, 2026

A'll these trait methods return futures that borrow &mut self. This makes doing anything other than imperative one-after-another calls to methods almost impossible. So the trait was rewritten to return owned futures. Except for len() is is_empty() which are now sync and infallible.

For more information see this issue in the hypercore repo.

  • decide what type data should be in RandomAccess.write

@cowlicks
Copy link
Member Author

To whom it may concern:

RandomAccess.write's data parameter is under consideration.

The write method currently takes &[u8], but since BoxFuture is 'static the data must either be cloned before being moved into the future, or the caller must ensure it lives long enough. We haven't settled on the best owned type for this parameter. Candidates are Vec<u8> (no new dependency, universal), Bytes (cheaply cloneable, idiomatic in async I/O) and keeping &[u8] with a lifetime-bound future (zero-copy but no longer 'static). Feedback welcome.

I'm leaning towards using Bytes but I will decide that after publishing this as an x.x.x-alpha version.

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