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

Splice for BytesMut #706

Open
Sytten opened this issue May 6, 2024 · 2 comments
Open

Splice for BytesMut #706

Sytten opened this issue May 6, 2024 · 2 comments

Comments

@Sytten
Copy link
Contributor

Sytten commented May 6, 2024

In my question to move from Arc<Vec<u8>> to BytesMut, I am facing a couple of missing methods I had on Vec.
One of them is splice (https://doc.rust-lang.org/std/vec/struct.Vec.html#method.splice).
I am guessing this method could go in BufMut?

@Darksonn
Copy link
Contributor

The Vec::splice method is complicated because it has to work with types that are not Copy. However, u8 is Copy, so it should not be too hard to emulate it with copy_within followed by truncate.

@Sytten
Copy link
Contributor Author

Sytten commented May 11, 2024

The hard part really is when the destination range is smaller than the source range since it requires at least one reallocation (if the size hint lower bound proves to be enough).

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

No branches or pull requests

2 participants