Unable to try_reclaim(..) a BytesMut allocation
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
Research direction
Start at the BytesMut::reserve entry point and trace how allocation ownership is handled when the buffer has shared handles. The work is done when a try_reclaim API follows the proposed success and failure semantics, with behavior checked for both sole and shared handles.
Written by the indexing model from the issue text.
Description
bytes_mut.reserve(..) makes the guarantee that the underlying allocation will be reclaimed when bytes_mut is the only remaining handle to it. However, when it isn't the only remaining handle, new space is allocated and the handle to the old allocation is discarded.
BytesMut should offer a method to request that the underlying allocation be reclaimed without discarding the old allocation when the attempt fails. Something along the lines of the following.
impl BytesMut {
/// Attempts to reclaim the underlying allocation.
///
/// The attempt will succeed iff this is the last remaining handle
/// to the allocation.
///
/// When the attempt succeeds, an empty `BytesMut` with the full
/// capacity of the allocation is returned. Otherwise, the original
/// handle is returned.
pub fn try_reclaim(self) -> Result<Self, Self>;
}
I'd be happy to implement this proposal and file a PR for it.
- Dominant language
- Rust
- Stars
- 2.3k
- Forks
- 355
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tokio-rs/bytes
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
-
Optimize Extend trait to have BytesMut::extend(&mut self, &[u8) compile to a `memcpy` when possible Open
Difficulty 3/5 1-2 days Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 55/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Difficulty 2/5 1-3 hours Newbie friendliness 68/100