Skip to content

More flexible and efficient Bytes representation#5670

Merged
laurmaedje merged 1 commit intomainfrom
bytes
Jan 8, 2025
Merged

More flexible and efficient Bytes representation#5670
laurmaedje merged 1 commit intomainfrom
bytes

Conversation

@laurmaedje
Copy link
Member

Any AsRef<[u8]> or AsRef<str> can now back the Bytes, so we can use types like the following without copying into a new vector: [u8; 8], EcoString, String. Of course, &'static [u8] is also possible, but this was the case before as well.

This also removes the From<&[u8]> and From<Vec<u8>> impls from Bytes because they may hide unnecessary copies and Bytes::new forces the caller to think more about what they want to pass in.

Any `AsRef<[u8]>` or `AsRef<str>` can now back the `Bytes`, so we can use types like the following without copying into a new vector: `[u8; 8]`, `EcoString`, `String`. Of course, `&'static [u8]` is also possible, but this was the case before as well.

This removes the `From<&[u8]>` and `From<Vec<u8>>` impls from `Bytes` because they may hide unnecessary copies and `Bytes::new` forces the caller to think more about what they want to pass in.
@laurmaedje laurmaedje added this pull request to the merge queue Jan 8, 2025
Merged via the queue into main with commit dacd6ac Jan 8, 2025
@laurmaedje laurmaedje deleted the bytes branch January 8, 2025 11: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